My environment:
macOS 10.14
Clion 2018.1.2
gcc-8.2
I want to use Clion to try the rocksdb. I add a new CMakeLists.txt file at examples directory.
CMakeLists.txt:
add_subdirectory(examples)
examples/CMakeLists.txt:
add_executable(s_test simple_example.cc)
target_link_libraries(s_test ${LIBS})
But when I build the s_test executable, I get the error as follows.
Linking CXX shared library librocksdb.dylib
Undefined symbols for architecture x86_64:
"google::FlagRegisterer::FlagRegisterer<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(char const*, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)", referenced from:
__static_initialization_and_destruction_0(int, int) in db_bench_tool.cc.o
__static_initialization_and_destruction_0(int, int) in trace_analyzer_tool.cc.o
"google::SetUsageMessage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
rocksdb::db_bench_tool(int, char**) in db_bench_tool.cc.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [librocksdb.5.17.0.dylib] Error 1
make[2]: *** [CMakeFiles/rocksdb-shared.dir/all] Error 2
make[1]: *** [examples/CMakeFiles/s_test.dir/rule] Error 2
And I already installed the gflags previously.
ls /usr/local/lib | grep gflags
libgflags.2.2.1.dylib
libgflags.2.2.dylib
libgflags.dylib
libgflags_nothreads.2.2.1.dylib
libgflags_nothreads.2.2.dylib
libgflags_nothreads.dylib
How to solve it? Thank you!
You will need to pull down the gflags package from git hub. I also use CLION.
So, this is the procedure I followed to pull down rocksdb and gflags:
~> cd CLionProjects
~/CLionProjects> git clone git#github.com:facebook/rocksdb.git
~/CLionProjects> cd rocksdb
~/CLionProjects/rocksdb> git clone git#github.com:gflags/gflags.git
I then created gflagss.cmake at
~/CLionProjects/rocksdb/cmake/modules
with the following content:
# - Find GFLAGS
set(GFLAGS_ROOT_DIR ./gflags/cmake-build-debug)
find_path(GFLAGS_INCLUDE_DIR
NAMES bzlib.h
HINTS ${GFLAGS_ROOT_DIR}/include)
find_library(GFLAGS_LIBRARIES
NAMES gflags
HINTS ${GFLAGS_ROOT_DIR}/lib)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(bzip2 DEFAULT_MSG BZIP2_LIBRARIES BZIP2_INCLUDE_DIR)
mark_as_advanced(
GFLAGS_LIBRARIES
GFLAGS_INCLUDE_DIR)
I then opened the gflags folder in CLion and built glfags.
I then opened a separate CLion window/folder for rocksdb and built that.
Related
I am new to c++ and I am using CLion on a Mac. I would like to use the boost 1.65.0 filesystem library. When I add the following import statement the console app doesn't compile.
#include <boost/filesystem.hpp>
I get the following error:
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
___cxx_global_var_init.2 in main.cpp.o
"boost::system::generic_category()", referenced from:
boost::system::error_category::std_category::equivalent(int, std::__1::error_condition const&) const in main.cpp.o
boost::system::error_category::std_category::equivalent(std::__1::error_code const&, int) const in main.cpp.o
___cxx_global_var_init in main.cpp.o
___cxx_global_var_init.1 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]: *** [sandbox] Error 1
make[2]: *** [CMakeFiles/sandbox.dir/all] Error 2
make[1]: *** [CMakeFiles/sandbox.dir/rule] Error 2
make: *** [sandbox] Error 2
CMake file:
cmake_minimum_required(VERSION 3.8)
project(sandbox)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES src/main.cpp)
find_package(Boost)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
add_executable(sandbox ${SOURCE_FILES})
target_link_libraries (sandbox ${Boost_LIBRARIES})
Other libraries such as the boost string library works fine. But I cant use the filesystem library. Any idea what I am doing wrong?
I am currently trying to compile a Contraction Hierachies implementation by KIT which requires Boost::Regex. The supplied Makefile already makes sure (and I have also double-checked this manually) that g++ is supplied with the -lboost_regex switch. If the library is not installed, g++ will complain.
So I installed the library from my package sources and tried compiling again. This time I am getting a huge load of linker errors regarding Boost::Regex. Here is a short excerpt:
main.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::unwind_extra_block(bool)':
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE18unwind_extra_blockEb[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE18unwind_extra_blockEb]+0x2c): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.o: In function `void boost::re_detail::raise_error<boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > >(boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::error_type)':
main.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0x7d): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
main.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0xb1): undefined reference to `boost::re_detail::raise_runtime_error(std::runtime_error const&)'
main.cpp:(.text._ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE[_ZN5boost9re_detail11raise_errorINS_20regex_traits_wrapperINS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEEEEvRKT_NS_15regex_constants10error_typeE]+0xcb): undefined reference to `boost::re_detail::get_default_error_string(boost::regex_constants::error_type)'
main.o: In function `__gnu_cxx::__normal_iterator<char const*, std::string> boost::re_detail::re_is_set_member<__gnu_cxx::__normal_iterator<char const*, std::string>, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >, unsigned int>(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::re_detail::re_set_long<unsigned int> const*, boost::re_detail::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, bool)':
main.cpp:(.text._ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb[_ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb]+0x17b): undefined reference to `boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const'
main.cpp:(.text._ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb[_ZN5boost9re_detail16re_is_set_memberIN9__gnu_cxx17__normal_iteratorIPKcSsEEcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEjEET_SB_SB_PKNS0_11re_set_longIT2_EERKNS0_10regex_dataIT0_T1_EEb]+0x4c0): undefined reference to `boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const'
main.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::extend_stack()':
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12extend_stackEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE12extend_stackEv]+0x18): undefined reference to `boost::re_detail::get_mem_block()'
main.o: In function `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_imp()':
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0xc): undefined reference to `boost::re_detail::get_mem_block()'
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0x19e): undefined reference to `boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)'
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0x254): undefined reference to `boost::re_detail::put_mem_block(void*)'
main.cpp:(.text._ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv[_ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE9match_impEv]+0x3c6): undefined reference to `boost::re_detail::put_mem_block(void*)'
This looks very much like the compiler did not find the library at all. In fact, when I don't supply the -lboost_regex switch the output remains the same (I ran a hash on it).
However, running the linker with the -Wl,--verbose switch as suggested in nuwen MinGW + Boost- error linking boost_regex shows that the library is found:
attempt to open /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_regex.so succeeded
-lboost_regex (/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_regex.so)
All I know is that this is likely a different boost version than what was around when the software was written (I don't know which. I am using 1.53 now.) but from looking at the code it seems it should still work. Also I am using the headers from this boost version so the compiler should already complain if function signatures have changed.
How can I get this to link? Am I missing something?
Linker switches are in the wrong order. make tries to do this:
g++ -lboost_regex -lboost_iostreams -o main main.o
This is what actually works (at least with gcc 4.8.1):
g++ -o main main.o -lboost_regex -lboost_iostreams
So to fix the compilation error you should substitue line 6 in the Makefile with the following:
$(CXX) -o $# $^ $(LIBS) $(LINK)
Boost regex (and other boost libs, probably) may also fail to link if you have multiple versions of boost available, and the linker path and include paths point to different versions (this happened to me with cmake when using find_package(Boost ...) where a path was specified while also having a different version installed in the system root.
The solution in the case of cmake was to add include_directories(${Boost_INCLUDE_DIRS}) to CMakeLists.txt as well as ensuring the correct link ordering in the target_link_libraries.
I built the i386 flavor of OpenCV locally on my Macbook running Lion, by using
cmake -G "Unix Makefiles" -D CMAKE_OSX_ARCHITECTURES=i386 -D CMAKE_C_FLAGS=-m32 -D CMAKE_CXX_FLAGS=-m32 ..
make -j8
sudo make install
Libraries built and published fine, and I've added them to my xcode project.
However, there are link errors when building my test app, and they seem to be name mangling issues.
Undefined symbols for architecture i386:
"cv::namedWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in main.o
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in main.o
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in main.o
Taking cv::imread as an example, it is exported from libopencv_highgui.dylib with the name:
00007510 (__TEXT,__text) external __ZN2cv6imreadERKSsi
while main.o is referencing the symbol
U __ZN2cv6imreadERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi
On the other hand, function __ZN2cv7waitKeyEi from the same dylib links fine.
Both the test app and the framework are for i386 arch.
Any ideas what might be causing this issue?
I've had the same problem. I think the issue could be that if you have used the MacPorts to compile your OpenCV libraries, they probably got built by the GCC according to it's Portfile. I switched the compiler used in the XCode (Apple LLVM 4.1) to the LLVM GCC 4.2 and now it works.
Hope it helps.
I just had the same problem and fixed it by using libstdc++ as the C++ standard library. It was defaulted to libc++
Under Project Build settings -> APPLE LLVM compiler 4.2 - Language -> C++ Standard Library
I have mad my own CMakeLists.txt file to build OpenNI samples. I successfully build NiSimpleViewer. But when try with NiUserTracker I get this error:
35 warnings generated.
Linking CXX executable main
ld: warning: path '/usr/lib/libOpenNI.dylib' following -L not a directory
Undefined symbols for architecture x86_64:
"DrawDepthMap(xn::DepthMetaData const&, xn::SceneMetaData const&)", referenced from:
glutDisplay() in main.cpp.o
"MyPoseInProgress(xn::PoseDetectionCapability&, char const*, unsigned int, XnPoseDetectionStatus, void*)", referenced from:
_main in main.cpp.o
"MyCalibrationInProgress(xn::SkeletonCapability&, unsigned int, XnCalibrationStatus, void*)", 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[2]: *** [main] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
This is the CMakeLists I use. Plese tell me what's wrong with it?
http://pastebin.com/SMYjjU35
The contents of folder outside build/ are
CMakeLists.txt Libs build opengles.cpp
GL SceneDrawer.cpp glh opengles.h
GLES SceneDrawer.h main.cpp
I guess, it's because of this line:
link_directories(${OPENNI_LIBRARY})
The link_directories() command sets path where libraries should be searched for, so you need something like ${OPENNI_LIBRARY_DIRS} there.
I'm creating a browser plugin that handles joystick input across all browser and platforms. It's working on Linux and Windows, but I'm having trouble linking to the OIS library in XCode.
I've built OIS and get libOIS.a and OIS.dylib and am linking them with CMake as follows:
find_library(CARBON NAMES Carbon)
find_library(IOKIT NAMES IOKit)
target_link_libraries(${PROJECT_NAME}
${PLUGIN_INTERNAL_DEPS}
${CARBON}
${IOKIT}
"${CMAKE_CURRENT_SOURCE_DIR}/lib/libOIS.a"
)
But I'm still getting errors every time I try to use the OIS classes from my code and build the project:
ld warning: in /Users/Lana/Documents/STRd6/boomsticks/Boomstick/lib/libOIS.a, missing required architecture x86_64 in file
Undefined symbols:
"OIS::InputManager::destroyInputSystem(OIS::InputManager*)", referenced from:
JoysticksHandler::~JoysticksHandler()in Joysticks.o
JoysticksHandler::~JoysticksHandler()in Joysticks.o
"OIS::InputManager::createInputSystem(std::multimap<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)", referenced from:
JoysticksHandler::initialize() in Joysticks.o
"OIS::InputManager::enableAddOnFactory(OIS::InputManager::AddOnFactories)", referenced from:
JoysticksHandler::initialize() in Joysticks.o
"OIS::InputManager::getNumberOfDevices(OIS::Type)", referenced from:
JoysticksHandler::initialize() in Joysticks.o
"typeinfo for OIS::Exception", referenced from:
GCC_except_table44 in Joysticks.o
"OIS::InputManager::createInputObject(OIS::Type, bool, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
JoysticksHandler::initialize() in Joysticks.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I don't know anything about XCode, but I was able to get the same code building with a very similar process on Linux and Windows.
The linker warning here gives you a clue:
ld warning: in /...k/lib/libOIS.a, missing required architecture x86_64 in file
The linker is telling you that you're trying to link in a library file that has no implementation for the x86_64 architecture. How did you build that library?
Either you're building a universal binary executable, and the symbols are just not there for the x86_64 version... or perhaps you have a header file for a newer version of the library, but have not updated the .a file, and the symbols you reference in your application code just don't exist in the .a file in your source tree...