use gcc to compile is ok:
gcc -o test_blob test_blob.cpp -D CPU_ONLY -lcaffe -lstdc++ -lglog
but at CLion, got this error:
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:
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?
It seems that your CMake project is very different than the gcc compilation. 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. The CMakeLists.txt file should also link those libraries. Your executable should really be test_blob and your project cannot be named caffe because you are using the caffe library. The CMakeLists.txt should be of this form:
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.
Related
I want to use rpclib from here. I started a new project with main.cpp and CMakeLists.txt and copied the rpclib as a subdirectory into my project:
My code is exactly the example from rpclib and looks like this:
#include <iostream>
#include "rpc/server.h"
void foo() {
std::cout << "foo was called!" << std::endl;
}
int main(int argc, char *argv[]) {
// Creating a server that listens on port 8080
rpc::server srv(8080);
// Binding the name "foo" to free function foo.
// note: the signature is automatically captured
srv.bind("foo", &foo);
// Binding a lambda function to the name "add".
srv.bind("add", [](int a, int b) {
return a + b;
});
// Run the server loop.
srv.run();
return 0;
}
and my CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.16)
project(RPC_Test)
set(CMAKE_CXX_STANDARD 14)
add_subdirectory(rpclib)
include_directories(rpclib/include)
add_executable(RPC_Test main.cpp)
As I understood, the line add_subdirectory(rpclib) takes care of adding the rpclib and builds its content during building the RPC_Test-Project. It seems, I am wrong. Nothing within rpclib gets build and the build-process RPC_Test fails with a linker-error:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/seba/CLionProjects/rpc-cpp/cmake-build-debug-system --target RPC_Test -- -j 3
Scanning dependencies of target RPC_Test
[ 50%] Building CXX object CMakeFiles/RPC_Test.dir/main.cpp.o
[100%] Linking CXX executable RPC_Test
Undefined symbols for architecture x86_64:
"rpc::detail::dispatcher::enforce_arg_count(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, unsigned long)", referenced from:
void rpc::detail::dispatcher::bind<void (*)()>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void (*)(), rpc::detail::tags::void_result const&, rpc::detail::tags::zero_arg const&)::'lambda'(clmdep_msgpack::v2::object const&)::operator()(clmdep_msgpack::v2::object const&) const in main.cpp.o
void rpc::detail::dispatcher::bind<main::$_0>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, main::$_0, rpc::detail::tags::nonvoid_result const&, rpc::detail::tags::nonzero_arg const&)::'lambda'(clmdep_msgpack::v2::object const&)::operator()(clmdep_msgpack::v2::object const&) const in main.cpp.o
"rpc::detail::dispatcher::enforce_unique_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
void rpc::detail::dispatcher::bind<void (*)()>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void (*)()) in main.cpp.o
void rpc::detail::dispatcher::bind<void (*)()>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, void (*)(), rpc::detail::tags::void_result const&, rpc::detail::tags::zero_arg const&) in main.cpp.o
void rpc::detail::dispatcher::bind<main::$_0>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, main::$_0) in main.cpp.o
void rpc::detail::dispatcher::bind<main::$_0>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, main::$_0, rpc::detail::tags::nonvoid_result const&, rpc::detail::tags::nonzero_arg const&) in main.cpp.o
"rpc::server::run()", referenced from:
_main in main.cpp.o
"rpc::server::server(unsigned short)", referenced from:
_main in main.cpp.o
"rpc::server::~server()", referenced from:
_main 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)
make[3]: *** [RPC_Test] Error 1
make[2]: *** [CMakeFiles/RPC_Test.dir/all] Error 2
make[1]: *** [CMakeFiles/RPC_Test.dir/rule] Error 2
make: *** [RPC_Test] Error 2
What is missing?
You're missing a target_link_libraries(RPC_Test PRIVATE rpc) after the definition of the RPC_Test target . rpc here is the name of the library target defined in rpclib's CMakeLists.txt, not just the base name of the resulting binary artifact.
When using a target name with target_link_libraries like that CMake will not only add -lrpc to the linker invocation, but also automatically add the include directories necessary to use the library and ensure that the rpc library is built before RPC_Test. In particular, this means you can also remove the include_directories call when you use target_link_libraries(RPC_Test PRIVATE rpc).
I'm following JetBrains's tutorial on an Apple Silicon computer. I installed boost with MacPorts (sudo port install boost), the version is 1.71 The build of tests.cpp file fails with the following error:
ld: warning: ignoring file /opt/local/lib/libboost_unit_test_framework-mt.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)", referenced from:
my_testsuite::addvalues_zero::test_method() in tests.cpp.o
my_testsuite::addvalues_negpos::test_method() in tests.cpp.o
"boost::test_tools::tt_detail::format_assertion_result(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>)", referenced from:
boost::test_tools::assertion::binary_expr<boost::test_tools::assertion::value_expr<int>, int, boost::test_tools::assertion::op::EQ<int, int, void> >::evaluate(bool) const in tests.cpp.o
"boost::unit_test::lazy_ostream::inst", referenced from:
boost::unit_test::lazy_ostream::instance() in tests.cpp.o
"boost::unit_test::unit_test_main(bool (*)(), int, char**)", referenced from:
_main in tests.cpp.o
"boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::basic_cstring<char const>)", referenced from:
my_testsuite::addvalues_zero_invoker() in tests.cpp.o
my_testsuite::addvalues_zero::test_method() in tests.cpp.o
my_testsuite::addvalues_negpos_invoker() in tests.cpp.o
my_testsuite::addvalues_negpos::test_method() in tests.cpp.o
"boost::unit_test::unit_test_log_t::instance()", referenced from:
___cxx_global_var_init in tests.cpp.o
"boost::unit_test::decorator::collector_t::instance()", referenced from:
___cxx_global_var_init.3 in tests.cpp.o
___cxx_global_var_init.6 in tests.cpp.o
___cxx_global_var_init.10 in tests.cpp.o
"boost::unit_test::framework::impl::master_test_suite_name_setter::master_test_suite_name_setter(boost::unit_test::basic_cstring<char const>)", referenced from:
___cxx_global_var_init.1 in tests.cpp.o
"boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::function<void ()> const&)", referenced from:
boost::unit_test::make_test_case(boost::function<void ()> const&, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long) in tests.cpp.o
"boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::decorator::collector_t&)", referenced from:
___cxx_global_var_init.3 in tests.cpp.o
"boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, boost::unit_test::decorator::collector_t&, unsigned long)", referenced from:
___cxx_global_var_init.6 in tests.cpp.o
___cxx_global_var_init.10 in tests.cpp.o
"boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(int)", referenced from:
___cxx_global_var_init.15 in tests.cpp.o
"boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char const>)", referenced from:
boost::unit_test::make_test_case(boost::function<void ()> const&, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long) in tests.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)
make[3]: *** [test/test] Error 1
make[2]: *** [test/CMakeFiles/test.dir/all] Error 2
make[1]: *** [test/CMakeFiles/test.dir/rule] Error 2
make: *** [test] Error 2
My code in tests.cpp:
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE my_unit_tests
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../calc.h"
BOOST_AUTO_TEST_SUITE(my_testsuite)
BOOST_AUTO_TEST_CASE(addvalues_zero)
{
BOOST_TEST(add(0, 0) == 0);
BOOST_TEST(add(-5, 5) == 0);
}
BOOST_AUTO_TEST_CASE(addvalues_negpos)
{
BOOST_TEST(add(-5, 10) == 5);
BOOST_TEST(add(-10, 5) == -5);
BOOST_TEST(add(5, 10) == 15);
}
BOOST_AUTO_TEST_SUITE_END()
My code in test/CMakeLists.txt:
set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
include_directories(${Boost_INCLUDE_DIR})
add_executable(test tests.cpp)
target_link_libraries(test ${Boost_LIBRARIES})
target_link_libraries(test test_lib)
I have the library in the cmake-build-debug folder and I have included the test subproject in the main CMakeLists.txt.
Add
set(CMAKE_OSX_ARCHITECTURES, arm64)
in the most beginning of the root CmakeLists.txt.
Probably, you'd need this as well:
set(CMAKE_SYSTEM_PROCESSOR arm64)
set(CMAKE_OSX_ARCHITECTURES arm64)
BTW, if you have these errors, maybe you use an outdated macOS version or you didn't download the XCode.
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,
With Clang specification,
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,
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.
Path,
You're not linking against libnormaliz
You need to configure cmake to link the library.
The first step is telling cmake how to find the library, for which you use 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:
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
target_link_libraries(untitled2 ${LIB_NORMALIZ})
Your CMakeLists.txt should look something like the following:
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)
I'm building a big project related to a simulation of a detector in physics.
I have to compile the project using CMAKE on macOS Sierra 10.12.5 and my processor architecture is 64-bits.
I built all the requirement programs using "homebrew".
I tried to compile in different CMAKE architecture modes:
cmake ../mu3e
cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 ../mu3e
cmake -DCMAKE_OSX_ARCHITECTURES=i386 ../mu3e
cmake -DCMAKE_OSX_ARCHITECTURES="ppc;i386" ../mu3e
cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;i386" ../mu3e
../mu3e is the directory of the source.
I always ended up with the same or similar error regarding the "Undefined symbols for architecture x86_64:" and "ld: symbol(s) not found for architecture x86_64":
[ 66%] Built target mu3eAnaFibreTrackStat
[ 66%] Building CXX object mu3eAna/Fibres/CMakeFiles/mu3eAnaFibreAna.dir/fibreana.cpp.o
[ 67%] Linking CXX shared library libmu3eAnaFibreAna.dylib
Undefined symbols for architecture x86_64:
"HitStatistics::processFrame(std::__1::map<unsigned int, std::__1::vector<fibreAnaTypes::hit_t, std::__1::allocator<fibreAnaTypes::hit_t> >, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, std::__1::vector<fibreAnaTypes::hit_t, std::__1::allocator<fibreAnaTypes::hit_t> > > > >*)", referenced from:
fibreAna::processFrame() in fibreana.cpp.o
"HitStatistics::HitStatistics(unsigned int)", referenced from:
fibreAna::setHitStat(bool) in fibreana.cpp.o
"TVersionCheck::TVersionCheck(int)", referenced from:
__GLOBAL__sub_I_fibreana.cpp in fibreana.cpp.o
"MPPCStatistics::processFrame(std::__1::map<unsigned int, std::__1::vector<fibreAnaTypes::sensor_t, std::__1::allocator<fibreAnaTypes::sensor_t> >, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, std::__1::vector<fibreAnaTypes::sensor_t, std::__1::allocator<fibreAnaTypes::sensor_t> > > > >*)", referenced from:
fibreAna::processFrame() in fibreana.cpp.o
"MPPCStatistics::MPPCStatistics(unsigned int, unsigned int)", referenced from:
fibreAna::setMPPCStat(bool) in fibreana.cpp.o
"FibreStatistics::processFrame(std::__1::map<unsigned int, std::__1::vector<fibreAnaTypes::fibre_t, std::__1::allocator<fibreAnaTypes::fibre_t> >, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, std::__1::vector<fibreAnaTypes::fibre_t, std::__1::allocator<fibreAnaTypes::fibre_t> > > > >*)", referenced from:
fibreAna::processFrame() in fibreana.cpp.o
"FibreStatistics::FibreStatistics(unsigned int, unsigned int, unsigned int)", referenced from:
fibreAna::setFibreStat(bool) in fibreana.cpp.o
"TrackStatistics::processFrame(std::__1::vector<fibreAnaTypes::track_t, std::__1::allocator<fibreAnaTypes::track_t> >*, std::__1::map<unsigned int, std::__1::vector<fibreAnaTypes::hit_t, std::__1::allocator<fibreAnaTypes::hit_t> >, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, std::__1::vector<fibreAnaTypes::hit_t, std::__1::allocator<fibreAnaTypes::hit_t> > > > >*)", referenced from:
fibreAna::processFrame() in fibreana.cpp.o
"TrackStatistics::TrackStatistics()", referenced from:
fibreAna::setTrackStat(bool) in fibreana.cpp.o
"FibreEndStatistics::processFrame(std::__1::map<unsigned int, std::__1::vector<fibreAnaTypes::fibreend_t, std::__1::allocator<fibreAnaTypes::fibreend_t> >, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, std::__1::vector<fibreAnaTypes::fibreend_t, std::__1::allocator<fibreAnaTypes::fibreend_t> > > > >*)", referenced from:
fibreAna::processFrame() in fibreana.cpp.o
"FibreEndStatistics::FibreEndStatistics(unsigned int, unsigned int, unsigned int)", referenced from:
fibreAna::setFibreEndStat(bool) in fibreana.cpp.o
"TChain::TChain(char const*, char const*)", referenced from:
fibreAna::fibreAna(char const*) in fibreana.cpp.o
"TClass::GetClass(std::type_info const&, bool, bool)", referenced from:
fibreAna::init() in fibreana.cpp.o
"TObject::operator delete(void*)", referenced from:
fibreAna::fibreAna(char const*) in fibreana.cpp.o
"TStorage::ObjectAlloc(unsigned long)", referenced from:
fibreAna::fibreAna(char const*) in fibreana.cpp.o
"TDataType::GetType(std::type_info const&)", referenced from:
fibreAna::init() in fibreana.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)
make[2]: *** [mu3eAna/Fibres/libmu3eAnaFibreAna.dylib] Error 1
make[1]: *** [mu3eAna/Fibres/CMakeFiles/mu3eAnaFibreAna.dir/all] Error 2
make: *** [all] Error 2
When compiling in Ubuntu 16.04 LTS, everything works correctly, which might give you a hint why this is not working.
Thank you for any possible advice and please let me know if you need further information.
I'm new to c++, so sorry if there is an obvious solution I'm missing. I'm trying to run this example code for dlib in c++. I'm getting this error...
In file included from /Users/john/ClionProjects/dlib/examples/face_detection_ex.cpp:41:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/gui_widgets.h:13:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/widgets.h:9:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/drawable.h:8:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_widgets/../gui_core.h:14:
In file included from /Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/xlib.h:4:
/Users/john/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/gui_core_kernel_2.h:11:2: error: "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it."
#error "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it."
^
/Users/johnoberhauser/ClionProjects/dlib/dlib/../dlib/image_processing/../gui_core/gui_core_kernel_2.h:12:2: error: "Also make sure you have libx11-dev installed on your system"
#error "Also make sure you have libx11-dev installed on your system"
I've tried going into /dlib/CMakeLists.txt and adding
set(DLIB_NO_GUI_SUPPORT OFF)
I know it's found the X11 package as I'm not getting a message from the cmake there (and I just installed XQuartz)
Also, I'm using Clion, so I'm not running cmake from the command line. And I'm on OSX
Edit: I tried removing the parts of the code that use the gui, just to see if it would work. But I then get this error:
Undefined symbols for architecture x86_64:
"_USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives", referenced from:
_dlib_check_consistent_assert_usage in main.cpp.o
"_cblas_saxpy", referenced from:
dlib::blas_bindings::cblas_axpy(int, float, float const*, int, float*, int) in main.cpp.o
"_cblas_sscal", referenced from:
dlib::blas_bindings::cblas_scal(int, float, float*) in main.cpp.o
"_dgesvd_", referenced from:
dlib::lapack::binding::gesvd(char, char, int, int, double*, int, double*, double*, int, double*, int, double*, int) in main.cpp.o
"_png_create_info_struct", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_create_read_struct", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_destroy_read_struct", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
dlib::png_loader::~png_loader() in libdlib.a(png_loader.cpp.o)
dlib::png_loader::~png_loader() in libdlib.a(png_loader.cpp.o)
"_png_get_bit_depth", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_color_type", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_image_height", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_image_width", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_get_rows", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_init_io", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_read_png", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_set_longjmp_fn", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
dlib::png_loader_user_error_fn_silent(png_struct_def*, char const*) in libdlib.a(png_loader.cpp.o)
"_png_set_palette_to_rgb", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_set_sig_bytes", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
"_png_sig_cmp", referenced from:
dlib::png_loader::read_image(char const*) in libdlib.a(png_loader.cpp.o)
ld: symbol(s) not found for architecture x86_64
I think this is a separate issue from the first one, but idk, maybe they are related? For this issue, I've tried doing what was mentioned here https://github.com/davisking/dlib/issues/57 I made the link for the first part, then added these lines to my cmakelist.txt
include_directories(../../../../usr/X11/lib)
include_directories(../../../../usr/local/include)
include_directories(../../../../usr/local/lib)
Didn't seem to fix the issue though.
Edit 2: So I think both these issues are resolved now. I think added those include_directories lines that I mentioned above help. Also, I started using cmake from the command line, instead of with clion.
However, I am now getting a new error :/
Undefined symbols for architecture x86_64:
"dlib::base_window::invalidate_rectangle(dlib::rectangle const&)", referenced from:
void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::base_window::set_size(int, int)", referenced from:
void dlib::image_window::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::image_window::add_overlay(std::__1::vector<dlib::image_display::overlay_rect, std::__1::allocator<dlib::image_display::overlay_rect> > const&)", referenced from:
void dlib::image_window::add_overlay<dlib::rgb_pixel>(std::__1::vector<dlib::rectangle, std::__1::allocator<dlib::rectangle> > const&, dlib::rgb_pixel) in main.cpp.o
"dlib::image_window::clear_overlay()", referenced from:
_main in main.cpp.o
"dlib::image_window::image_window()", referenced from:
_main in main.cpp.o
"dlib::image_window::~image_window()", referenced from:
_main in main.cpp.o
"dlib::popup_menu_region::disable()", referenced from:
void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::scrollable_region::set_total_rect_size(unsigned long, unsigned long)", referenced from:
void dlib::image_display::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
"dlib::draw_sunken_rectangle(dlib::canvas const&, dlib::rectangle const&, unsigned char)", referenced from:
dlib::scrollable_region_style_default::draw_scrollable_region_border(dlib::canvas const&, dlib::rectangle const&, bool) const in main.cpp.o
"dlib::image_display::get_image_display_rect() const", referenced from:
void dlib::image_window::set_image<dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > >(dlib::array2d<unsigned char, dlib::memory_manager_stateless_kernel_1<char> > const&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
One issue after another :/
Edit 3: Success! So I was using Clion for compiling. Even though the cmake from clion is the same version as the cmake I'm using in the command line, it just didn't work for some reason.
I solved this by deleting the "cmake-build-debug" directory.
Then reopen the project(CLion will regenerate it).
It seems there remain some cache files would affect the compiling.
But before this step, please make sure you do install XQuartz.