I'm trying to use libnormaliz library in Clion. However, it is directly linked from its path i.e. /Users/soner/Downloads/normaliz-3.4.0/source/libnormaliz
by CMake include_directories(/Users/soner/Downloads/normaliz-3.4.0/source/libnormaliz)
. I've downloaded its released version. But the error appears when run,
我正在尝试在Clion中使用libnormaliz库。但是,它通过CMake include_directories(/Users/soner/Downloads/normaliz-3.4.0/source/libnormaliz)与其路径直接链接,即/Users/soner/Downloads/normaliz-3.4.0/source/libnormaliz。我已下载其发布的版本。但运行时出现错误,
With Clang specification,
有了Clang规范,
Undefined symbols for architecture x86_64:
"libnormaliz::Cone<int>::Cone(libnormaliz::Type::InputType, std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > > const&)", referenced from:
_main in main.cpp.o
"libnormaliz::Cone<int>::~Cone()", referenced from:
_main in main.cpp.o
"std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
"std::logic_error::logic_error(char const*)", referenced from:
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
"std::length_error::~length_error()", referenced from:
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
"std::terminate()", referenced from:
___clang_call_terminate in main.cpp.o
"typeinfo for std::length_error", referenced from:
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
"vtable for std::length_error", referenced from:
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"operator delete(void*)", referenced from:
std::__1::__vector_base<int, std::__1::allocator<int> >::~__vector_base() in main.cpp.o
std::__1::__vector_base<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::~__vector_base() in main.cpp.o
"operator new(unsigned long)", referenced from:
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
"___cxa_allocate_exception", referenced from:
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
"___cxa_begin_catch", referenced from:
___clang_call_terminate in main.cpp.o
"___cxa_free_exception", referenced from:
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
"___cxa_throw", referenced from:
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
"___gxx_personality_v0", referenced from:
_main in main.cpp.o
std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main.cpp.o
std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main.cpp.o
std::__1::vector<int, std::__1::allocator<int> >::vector(std::__1::vector<int, std::__1::allocator<int> > const&) in main.cpp.o
Dwarf Exception Unwind Info (__eh_frame) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Without Clang specification,
没有Clang规范,
Undefined symbols for architecture x86_64:
"libnormaliz::Cone<int>::Cone(libnormaliz::Type::InputType, std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > > const&)", referenced from:
_main in main.cpp.o
"libnormaliz::Cone<int>::~Cone()", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
The code,
#include <libnormaliz/libnormaliz.h>
#include <libnormaliz/cone.h>
#include <vector>
int main() {
std::vector<std::vector <int> > data { {1,1,1}, {2,2,2} };
libnormaliz::Type::InputType type = libnormaliz::Type::cone;
/* runs well up to here */
libnormaliz::Cone<int> MyCone = libnormaliz::Cone<int>(type, data);
return 0;
}
CMakeLists.txt,
cmake_minimum_required(VERSION 3.8)
project(untitled2)
set(CMAKE_CXX_STANDARD 14)
set(LIB_NORMALIZ_PATH /Users/soner/Downloads/normaliz-3.4.0/source/libnormaliz)
find_library(
LIB_NORMALIZ
libnormaliz
PATHS
${LIB_NORMALIZ_PATH}
)
if (NOT FOUND_LIB_NORMALIZ)
message(SEND_ERROR "Unable to find libnormaliz")
endif()
set(SOURCE_FILES main.cpp)
add_executable(untitled2 ${SOURCE_FILES})
target_link_libraries(untitled2 ${LIB_NORMALIZ})
target_include_directories(untitled2 PUBLIC ${LIB_NORMALIZ_PATH})
Its output,
CMake Error at CMakeLists.txt:16 (message):
Unable to find libnormaliz
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIB_NORMALIZ
linked by target "untitled2" in directory /Users/soner/CLionProjects/untitled2
It is from its reference manual.
它来自参考手册。
1 个解决方案
#1
0
You're not linking against libnormaliz
你没有链接到libnormaliz
You need to configure cmake to link the library.
您需要配置cmake来链接库。
The first step is telling cmake how to find the library, for which you use find_library
第一步是告诉cmake如何找到你使用find_library的库
find_library(
LIB_NORMALIZ
libnormaliz
PATHS
/Users/soner/Downloads/normaliz-3.4.0/source/libnormaliz
)
You can verify if cmake was able to find it:
您可以验证cmake是否能够找到它:
if (NOT FOUND_LIB_NORMALIZ)
message(FATAL_ERROR "Unable to find libnormaliz")
endif()
Once cmake has found the library, you then need to link it to your target using target_link_libraries
一旦cmake找到了库,您就需要使用target_link_libraries将其链接到目标
target_link_libraries(untitled2 ${LIB_NORMALIZ})
Your CMakeLists.txt
should look something like the following:
您的CMakeLists.txt应如下所示:
cmake_minimum_required(VERSION 3.8)
project(untitled2)
set(CMAKE_CXX_STANDARD 14)
set(LIB_NORMALIZ_PATH /Users/soner/Downloads/normaliz-3.4.0/source/libnormaliz)
find_library(
LIB_NORMALIZ
libnormaliz
PATHS
${LIB_NORMALIZ_PATH}
)
if (NOT FOUND_LIB_NORMALIZ)
message(SEND_ERROR "Unable to find libnormaliz")
endif()
set(SOURCE_FILES main.cpp)
add_executable(untitled2 ${SOURCE_FILES})
target_link_libraries(untitled2 ${LIB_NORMALIZ})
target_include_directories(untitled2 PUBLIC ${LIB_NORMALIZ_PATH})
(Note I've changed include_directories
to target_include_directories
as this is idiomatic of modern cmake)
(注意我已将include_directories更改为target_include_directories,因为这是现代cmake的惯用语)
#1
0
You're not linking against libnormaliz
你没有链接到libnormaliz
You need to configure cmake to link the library.
您需要配置cmake来链接库。
The first step is telling cmake how to find the library, for which you use find_library
第一步是告诉cmake如何找到你使用find_library的库
find_library(
LIB_NORMALIZ
libnormaliz
PATHS
/Users/soner/Downloads/normaliz-3.4.0/source/libnormaliz
)
You can verify if cmake was able to find it:
您可以验证cmake是否能够找到它:
if (NOT FOUND_LIB_NORMALIZ)
message(FATAL_ERROR "Unable to find libnormaliz")
endif()
Once cmake has found the library, you then need to link it to your target using target_link_libraries
一旦cmake找到了库,您就需要使用target_link_libraries将其链接到目标
target_link_libraries(untitled2 ${LIB_NORMALIZ})
Your CMakeLists.txt
should look something like the following:
您的CMakeLists.txt应如下所示:
cmake_minimum_required(VERSION 3.8)
project(untitled2)
set(CMAKE_CXX_STANDARD 14)
set(LIB_NORMALIZ_PATH /Users/soner/Downloads/normaliz-3.4.0/source/libnormaliz)
find_library(
LIB_NORMALIZ
libnormaliz
PATHS
${LIB_NORMALIZ_PATH}
)
if (NOT FOUND_LIB_NORMALIZ)
message(SEND_ERROR "Unable to find libnormaliz")
endif()
set(SOURCE_FILES main.cpp)
add_executable(untitled2 ${SOURCE_FILES})
target_link_libraries(untitled2 ${LIB_NORMALIZ})
target_include_directories(untitled2 PUBLIC ${LIB_NORMALIZ_PATH})
(Note I've changed include_directories
to target_include_directories
as this is idiomatic of modern cmake)
(注意我已将include_directories更改为target_include_directories,因为这是现代cmake的惯用语)