[英]macos: how to use CLion for caffe?
use gcc to compile is ok: 使用gcc编译是可以的:
gcc -o test_blob test_blob.cpp -D CPU_ONLY -lcaffe -lstdc++ -lglog
gcc -o test_blob test_blob.cpp -D CPU_ONLY -lcaffe -lstdc ++ -lglog
but at CLion, got this error: 但是在CLion,出现此错误:
Undefined symbols for architecture x86_64:
"caffe::Blob<float>::mutable_cpu_data()", referenced from:
_main in main.cpp.o
"caffe::Blob<float>::Reshape(int, int, int, int)", referenced from:
_main in main.cpp.o
"google::LogMessage::stream()", referenced from:
caffe::Blob<float>::LegacyShape(int) const in main.cpp.o
caffe::Blob<float>::offset(int, int, int, int) const in main.cpp.o
caffe::Blob<float>::CanonicalAxisIndex(int) const in main.cpp.o
"google::LogMessageFatal::LogMessageFatal(char const*, int, google::CheckOpString const&)", referenced from:
caffe::Blob<float>::LegacyShape(int) const in main.cpp.o
caffe::Blob<float>::offset(int, int, int, int) const in main.cpp.o
caffe::Blob<float>::CanonicalAxisIndex(int) const in main.cpp.o
"google::LogMessageFatal::~LogMessageFatal()", referenced from:
caffe::Blob<float>::LegacyShape(int) const in main.cpp.o
caffe::Blob<float>::offset(int, int, int, int) const in main.cpp.o
caffe::Blob<float>::CanonicalAxisIndex(int) const in main.cpp.o
"google::base::CheckOpMessageBuilder::ForVar2()", referenced from:
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*) in main.cpp.o
"google::base::CheckOpMessageBuilder::NewString[abi:cxx11]()", referenced from:
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*) in main.cpp.o
"google::base::CheckOpMessageBuilder::CheckOpMessageBuilder(char const*)", referenced from:
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*) in main.cpp.o
"google::base::CheckOpMessageBuilder::~CheckOpMessageBuilder()", referenced from:
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*) in main.cpp.o
"caffe::Blob<float>::sumsq_data() const", referenced from:
_main in main.cpp.o
"caffe::Blob<float>::cpu_data() const", referenced from:
caffe::Blob<float>::data_at(int, int, int, int) const in main.cpp.o
"caffe::Blob<float>::asum_data() const", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [caffe] Error 1
make[2]: *** [CMakeFiles/caffe.dir/all] Error 2
make[1]: *** [CMakeFiles/caffe.dir/rule] Error 2
make: *** [caffe] Error 2
here is my CMakeLists.txt: 这是我的CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(caffe) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(USE_libstdcpp:BOOL false)
set(CMAKE_C_COMPILER "/usr/local/Cellar/gcc/7.2.0/bin/")
set(SOURCE_FILES main.cpp)
add_executable(caffe ${SOURCE_FILES})
target_compile_definitions(caffe PUBLIC CPU_ONLY=on)
what should I edit CMakeLists.txt? 我应该如何编辑CMakeLists.txt?
It seems that your CMake project is very different than the gcc
compilation. 看来您的CMake项目与
gcc
编译有很大不同。 I'll try to reconcile the two. 我会尝试调和两者。
First, the -l
flag for gcc
refers to the libraries that should be linked to the executable after compiling. 首先,
gcc
的-l
标志引用编译后应链接到可执行文件的库。 The CMakeLists.txt file should also link those libraries. CMakeLists.txt文件也应链接这些库。 Your executable should really be
test_blob
and your project cannot be named caffe
because you are using the caffe
library. 您的可执行文件实际上应该是
test_blob
并且您的项目不能命名为caffe
因为您正在使用caffe
库。 The CMakeLists.txt should be of this form: CMakeLists.txt的格式应为:
cmake_minimum_required(VERSION 3.5) # using modern CMake
project(blob) # names your project
find_package(glog) # finds your installation of glog
find_package(caffe) # finds your installation of caffe
set(CMAKE_CXX_STANDARD 11) # sets the "-std=c++11" flag
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_COMPILER "/usr/local/Cellar/gcc/7.2.0/bin/")
set(SOURCE_FILES test_blob.cpp)
add_executable(test_blob ${SOURCE_FILES}) # creates the executable
target_link_libraries(test_blob glog caffe) # links the test_blob target to glog and caffe
target_compile_definitions(test_blob PUBLIC CPU_ONLY=on)
This should fix your linker error. 这应该可以解决您的链接器错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.