使用 cmake 编译带有 v8 库的 C++ 程序
Compiling a C++ program with v8 library with cmake
我一直在使用 v8 C++ 库处理一个项目,我曾经使用 Makefile 编译它,但在某种程度上,我使用 CLion 并且我想调试,我不得不使用CMakeLists.txt
文件。
我遇到的问题是制作文件正在工作,但不是 cmake...
这是生成文件:
NAME = project
SRC = src/main.cpp
OBJ = $(SRC:.cpp=.o)
CXXFLAGS = -Iv8/include -std=c++11
LIBV8 = -Lv8/out/native/obj.target/third_party/icu/. -Lv8/out/native/obj.target/src/. -Wl,--start-group -lv8_base -lv8_libbase -lv8_external_snapshot -lv8_libplatform -lv8_libsampler -licuuc -licui18n -Wl,--end-group
all: $(NAME)
$(NAME): $(OBJ)
g++ -pthread -lSDL2 $^ -o $@ $(CXXFLAGS) $(LIBV8) -lrt -ldl
这是我制作的CMake版本:
cmake_minimum_required(VERSION 2.8.4)
project(Project CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories(${CMAKE_SOURCE_DIR}/v8/include)
include_directories(/usr/include/SDL2)
set(SDL2_LIBRARY /usr/lib/x86_64-linux-gnu/libSDL2.a)
find_package(Threads)
set(LIBV8
v8_base
v8_libbase
v8_external_snapshot
v8_libplatform
v8_libsampler
icuuc
icui18n
rt
dl
)
link_directories(
${CMAKE_SOURCE_DIR}/v8/out/native/obj.target/src/
${CMAKE_SOURCE_DIR}/v8/out/native/obj.target/third_party/icu/
${CMAKE_SOURCE_DIR}/v8/build/linux/debian_jessie_amd64-sysroot/usr/lib/x86_64-linux-gnu/
)
file(GLOB_RECURSE SOURCES
${CMAKE_SOURCE_DIR}/src/main.cpp
)
add_executable(project ${SOURCES})
target_link_libraries(project ${CMAKE_THREAD_LIBS_INIT} ${SDL2_LIBRARY} ${LIBV8})
我认为我已经正确链接了所有必要的库,但是当我使用 CMake 版本编译时,我有很多这样的错误(它们对于我的终端来说太多了,所以我只放一个片段,"référence indéfinie vers"的意思是"未定义的引用"(:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormatC2EPKdPKaPKNS_13UnicodeStringEi+0x43): référence indéfinie vers « icu_59::MessagePattern::MessagePattern(UErrorCode&) »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::ChoiceFormat(icu_59::ChoiceFormat const&) »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormatC2ERKS0_+0x3f): référence indéfinie vers « icu_59::MessagePattern::MessagePattern(icu_59::MessagePattern const&) »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::ChoiceFormat(icu_59::UnicodeString const&, UParseError&, UErrorCode&) »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormatC2ERKNS_13UnicodeStringER11UParseErrorR10UErrorCode+0x35): référence indéfinie vers « icu_59::MessagePattern::MessagePattern(UErrorCode&) »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::operator==(icu_59::Format const&) const »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZNK6icu_5912ChoiceFormateqERKNS_6FormatE+0x3a): référence indéfinie vers « icu_59::MessagePattern::operator==(icu_59::MessagePattern const&) const »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::operator=(icu_59::ChoiceFormat const&) »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormataSERKS0_+0x39): référence indéfinie vers « icu_59::MessagePattern::operator=(icu_59::MessagePattern const&) »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::~ChoiceFormat() »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormatD2Ev+0x13): référence indéfinie vers « icu_59::MessagePattern::~MessagePattern() »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::~ChoiceFormat() »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormatD0Ev+0x13): référence indéfinie vers « icu_59::MessagePattern::~MessagePattern() »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::applyPattern(icu_59::UnicodeString const&, UErrorCode&) »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormat12applyPatternERKNS_13UnicodeStringER10UErrorCode+0x17): référence indéfinie vers « icu_59::MessagePattern::parseChoiceStyle(icu_59::UnicodeString const&, UParseError*, UErrorCode&) »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::applyPattern(icu_59::UnicodeString const&, UParseError&, UErrorCode&) »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormat12applyPatternERKNS_13UnicodeStringER11UParseErrorR10UErrorCode+0x12): référence indéfinie vers « icu_59::MessagePattern::parseChoiceStyle(icu_59::UnicodeString const&, UParseError*, UErrorCode&) »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::format(double, icu_59::UnicodeString&, icu_59::FieldPosition&) const »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZNK6icu_5912ChoiceFormat6formatEdRNS_13UnicodeStringERNS_13FieldPositionE+0x8e): référence indéfinie vers « icu_59::MessagePattern::getNumericValue(icu_59::MessagePattern::Part const&) const »
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZNK6icu_5912ChoiceFormat6formatEdRNS_13UnicodeStringERNS_13FieldPositionE+0x144): référence indéfinie vers « icu_59::MessageImpl::appendSubMessageWithoutSkipSyntax(icu_59::MessagePattern const&, int, icu_59::UnicodeString&) »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::findSubMessage(icu_59::MessagePattern const&, int, double) »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormat14findSubMessageERKNS_14MessagePatternEid+0x6e): référence indéfinie vers « icu_59::MessagePattern::getNumericValue(icu_59::MessagePattern::Part const&) const »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::parseArgument(icu_59::MessagePattern const&, int, icu_59::UnicodeString const&, icu_59::ParsePosition&) »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZN6icu_5912ChoiceFormat13parseArgumentERKNS_14MessagePatternEiRKNS_13UnicodeStringERNS_13ParsePositionE+0x5d): référence indéfinie vers « icu_59::MessagePattern::getNumericValue(icu_59::MessagePattern::Part const&) const »
/home/xobtah/v8_Build/v8/out/native/obj.target/icui18n/third_party/icu/source/i18n/choicfmt.o: dans la fonction « icu_59::ChoiceFormat::clone() const »:
../third_party/icu/source/i18n/choicfmt.cpp:(.text._ZNK6icu_5912ChoiceFormat5cloneEv+0x4d): référence indéfinie vers « icu_59::MessagePattern::MessagePattern(icu_59::MessagePattern const&) »
collect2: error: ld returned 1 exit status
CMakeFiles/project.dir/build.make:95: recipe for target 'project' failed
make[2]: *** [project] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/project.dir/all' failed
make[1]: *** [CMakeFiles/project.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
非常感谢您的关注,我很感激!
编辑:make VERBOSE=1
链接:
[ 50%] Linking CXX executable project
/opt/cmake-3.7.1-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/project.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++11 CMakeFiles/project.dir/src/main.cpp.o -o project -L/home/xobtah/Project/v8/out/native/obj.target/src -L/home/xobtah/Project/v8/out/native/obj.target/third_party/icu -L/home/xobtah/Project/v8/build/linux/debian_jessie_amd64-sysroot/usr/lib/x86_64-linux-gnu -Wl,-rpath,/home/xobtah/Project/v8/out/native/obj.target/src:/home/xobtah/Project/v8/out/native/obj.target/third_party/icu:/home/xobtah/Project/v8/build/linux/debian_jessie_amd64-sysroot/usr/lib/x86_64-linux-gnu -rdynamic -lpthread -Wl,-Bstatic -lSDL2 -Wl,-Bdynamic -lv8_base -lv8_libbase -lv8_external_snapshot -lv8_libplatform -lv8_libsampler -licuuc -licui18n -lrt -ldl
您可能需要-Wl,--start-group
并-Wl,--end-group
target_link_libraries()
中的实际 v8 库。
如果您的目标是复制生成文件,则生成文件"LIBV8"中的库与 CMake "LIBV8" 中的库不同。
相关文章:
- c++库的公共头文件中应该包含什么
- 序列化,没有库的整数,得到奇怪的结果
- 停止cmake target_link_libraries将插件中静态库的两个对象文件链接到静态库本身
- 针对遗留库的链接:来自预制makefile的-lgfortranbegin
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- Android Studio 中带有静态库的原生C++代码
- 如何在OpenSSL库的名称中添加后缀'd'?
- 在OSX上使用CMake将Adobe的XMP工具包构建为共享库的最简单方法是什么?
- 为什么提升图库的 read_graphviz() 函数会改变节点的索引
- 在Visual Studio C++项目中包含源库的正确方法是什么?
- 良好做法:如何定义用于编译的外部库的路径
- 使用 CImg 库的 std::min 和 std::max 的编译问题
- 使用指针在存在特征库的情况下动态分配 c++ 中的矩阵
- CMake:我们可以为一组不形成可执行文件或库的特定文件指定包含目录吗?
- 将共享库的搜索路径更改为生成文件中提供的 rpath
- 编译依赖于 QTCore 库的 WASM
- 在不使用字符串库的情况下输入字符*
- 如何公开库的枚举,以便我的代码不必键入整个命名空间来使用该枚举?
- 如何在公共头文件中向库的用户公开枚举,同时在内部使用它?
- 获取 clang++:错误:在编译文件系统库的代码时