googletest Undefined symbols for architecture x86_64 error - c++

Let GTEST_DIR be the environment variable storing the path to the googletest directory. (I cloned googletest-master from googletest's github repo.)
I cd'ed into $GTEST_DIR, did a mkdir build && cd build, then executed the following command :
cmake .. -DCMAKE_C_COMPILER=$GNU-6.0.0/bin/gcc-6.0.0 -DCMAKE_CXX_COMPILER=$GNU-6.0.0/bin/g++-6.0.0
where GNU-6.0.0 is the path to my gnu install. This generated a Makefile inside $GTEST_DIR/build that I tweaked as follows : I've added
CC = $GNU-6.0.0/bin/gcc-6.0.0
CXX = $GNU-6.0.0/bin/g++-6.0.0
at its beginning, to be sure that the c and c++ compilers that will be used will be those I want to be used. Then I ran make which produced archive files libgtest.a and libgtest_main.a inside $GTEST_DIR/build.
Next step : in a same folder I put a main test source file main.cpp containg :
#include "path/to/gtest.h"
int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}
and a dummy test dummy_test.cpp containing :
#include "path/to/gtest.h"
TEST(dummy_test, test1)
{
EXPECT_EQ(1,1);
}
and a Makefile containing :
CC = gcc-6.0.0
CXX = g++-6.0.0
CPPFLAGS += -isystem $(GTEST_DIR)/include
LDFLAGS := -L/usr/lib -lpthread -L$(GTEST_DIR)/build -lgtest
all :
$(CXX) -o cpptests $(CPPFLAGS) ./main.cpp ./dummy_test.cpp $(LDFLAGS)
clean :
rm -rf ./cpptests
Running make I have this output :
Undefined symbols for architecture x86_64:
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::end() const", referenced from:
testing::internal::XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in libgtest.a(gtest-all.cc.o)
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::data() const", referenced from:
testing::internal::PrintStringTo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_ostream<char, std::char_traits<char> >*) in libgtest.a(gtest-all.cc.o)
__gnu_cxx::__enable_if<std::__is_char<char>::__value, bool>::__type std::operator==<char>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in libgtest.a(gtest-all.cc.o)
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long) const", referenced from:
bool testing::(anonymous namespace)::IsSubstringPred<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in libgtest.a(gtest-all.cc.o)
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char, unsigned long) const", referenced from:
testing::internal::SplitString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*) in libgtest.a(gtest-all.cc.o)
testing::internal::FormatDeathTestOutput(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in libgtest.a(gtest-all.cc.o)
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const", referenced from:
testing::internal::(anonymous namespace)::SplitEscapedString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in libgtest.a(gtest-all.cc.o)
...
...
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
The entire output is in this snippet while the output of nm libgtest.a is in this snippet.
Precision : I am under mac os x 10.10.5. As I want to continue working, developping code and testing it, while the aforementionned error with gcc/g++ 6.0.0 is solved, I tried to switch to another compiler : clang, and I remarked that I had no error at all with it.
Remark libgtest.a was initially (that is, before I asked this question) built "by error" with clang and used in tests with g++-6.1.0 when I encountered the error, that's why I decided to rebuild libgtest.a with g++-6.1.0, thinking that it would solve the problem, but it didn't, which led me to post here.

The problem seems to be due to some linking issues. Have you used the linker flags correctly. For gtest, we need to compile with -lgtest and the linker can link it correctly. Similarly, we need to have the flags for all possible libraries that we are linking against.
The code
TEST(dummy_test, test1) {
EXPECT_EQ(1,1); }
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); }
compiles perfectly for me with command
clang++ -std=c++11 main.cpp -lgtest
and I could run the single test without an issue.

I was getting following error
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
with the command
/usr/bin/g++ -g testgoogletestsetup.cpp -std=c++11 -o testgoogletestsetup -lgtest
Solution:
Library gtest_main needs to be linked (and the library gtest too) to compile it successfully. For that provide the linker flags as -lgtest_main as shown in below command.
/usr/bin/g++ -g testgoogletestsetup.cpp -std=c++11 -o testgoogletestsetup -lgtest -lgtest_main

Related

getting "undefined reference to `check' "error on Windows

I try to connect a DB to C++ with the Connector C++ 8.0.
When I compile a really simple code :
#include <iostream>
#include <jdbc.h>
int main(){
sql::Driver *driver;
driver = get_driver_instance();
return 0;
}
I get this error:
c:/program files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\newva\AppData\Local\Temp\ccjFB5x8.o:Main.cpp:(.text+0x1f): undefined reference to `check(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
c:/program files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\newva\AppData\Local\Temp\ccjFB5x8.o:Main.cpp:(.text+0x53): undefined reference to `check(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >
const&)'
collect2.exe: error: ld returned 1 exit status
When I comment the "driver = get_driver_instance();" line, the code compile.
I compile with a Makefile :
MYSQL_CONCPP_DIR = "C:\Program Files\MySQL\Connector C++ 8.0"
CPPFLAGS=-I $(MYSQL_CONCPP_DIR)\include\mysql -L $(MYSQL_CONCPP_DIR)\lib64\vs14
LDLIBS=-lmysqlcppconn
CXXFLAGS=-std=c++20
result.exe:Main.cpp
g++ Main.cpp ${CXXFLAGS} ${CPPFLAGS} ${LDLIBS} -o result.exe
I am on Windows 10.
Connector C++ has 2 APIs.
JDBC (the one you are using)
X DevAPI
You are linking with mysqlcppconn8 which is DevAPI. You should link with mysqlcppconn.
Both are bundled on the same package.

GTest linker errors on Ubuntu 20.10

I have the following errors on Ubuntu 20.04:
[1/1] Linking CXX executable bin/project_2022_matrix_tests
FAILED: bin/project_2022_matrix_tests
: && /usr/bin/c++ -g CMakeFiles/project_2022_matrix_tests.dir/CException.cpp.o CMakeFiles/project_2022_matrix_tests.dir/tests/CException_unit_tests.cpp.o CMakeFiles/project_2022_matrix_tests.dir/tests/main_unit_tests.cpp.o -o bin/project_2022_matrix_tests -L/home/username/.conan/data/gtest/cci.20210126/_/_/package/71c983c52942eb4756e4bd60e4cbec9fd7557e5d/lib -Wl,-rpath,/home/username/.conan/data/gtest/cci.20210126/_/_/package/71c983c52942eb4756e4bd60e4cbec9fd7557e5d/lib -lgtest_main -lgmock_main -lgmock -lgtest -lpthread -lpthread && :
/usr/bin/ld : CMakeFiles/project_2022_matrix_tests.dir/tests/CException_unit_tests.cpp.o : in the function « testing::AssertionResult::AppendMessage(testing::Message const&) » :
/home/username/.conan/data/gtest/cci.20210126/_/_/package/71c983c52942eb4756e4bd60e4cbec9fd7557e5d/include/gtest/gtest.h:357 : undefined reference to « testing::Message::GetString[abi:cxx11]() const »
/usr/bin/ld : CMakeFiles/project_2022_matrix_tests.dir/tests/CException_unit_tests.cpp.o : in the function « testing::AssertionResult testing::internal::CmpHelperEQFailure<CException*, decltype(nullptr)>(char const*, char const*, CException* const&, decltype(nullptr) const&) » :
/home/username/.conan/data/gtest/cci.20210126/_/_/package/71c983c52942eb4756e4bd60e4cbec9fd7557e5d/include/gtest/gtest.h:1529 : undefined reference to « testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) »
/usr/bin/ld : CMakeFiles/project_2022_matrix_tests.dir/tests/CException_unit_tests.cpp.o : in the function « testing::AssertionResult testing::internal::CmpHelperEQFailure<char*, decltype(nullptr)>(char const*, char const*, char* const&, decltype(nullptr) const&) » :
/home/username/.conan/data/gtest/cci.20210126/_/_/package/71c983c52942eb4756e4bd60e4cbec9fd7557e5d/include/gtest/gtest.h:1529 : undefined reference to « testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) »
/usr/bin/ld : CMakeFiles/project_2022_matrix_tests.dir/tests/CException_unit_tests.cpp.o : in the function « testing::AssertionResult testing::internal::CmpHelperEQFailure<int, int>(char const*, char const*, int const&, int const&) » :
/home/username/.conan/data/gtest/cci.20210126/_/_/package/71c983c52942eb4756e4bd60e4cbec9fd7557e5d/include/gtest/gtest.h:1529 : undefined reference to « testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) »
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.21)
project(project_2022_matrix_tests)
set(CMAKE_CXX_STANDARD 14)
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
else()
message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()
find_package(GTest REQUIRED)
include_directories(.)
enable_testing()
add_executable(project_2022_matrix_tests
CException.cpp
CException.h
CMatrix.cpp
CMatrix.h
CIndexableMatrix.h
main.cpp)
add_executable(project_2022_matrix_tests_tests
CException.cpp
CException.h
tests/CException_unit_tests.cpp tests/main_unit_tests.cpp tests/CMatrix_unit_tests.cpp)
target_link_libraries(project_2022_matrix_tests_tests gtest)
I have to say this works on CLion on macOS but for some reasons, not on Ubuntu...
If you need/want more information, please ask.
Thanks for your future reply.
To use the solution that was posted as a comment, just edit the .conan/profiles/default and change the line compiler.libcxx to set the value to libstdc++11.

Googletest: CLANG compiles where GCC fails

Here is a very simple script using gtest (saved in file gt.cpp)
#include<gtest/gtest.h>
double timesTwo(double x){return x*2;}
TEST(testTimesTwo, integerTests){EXPECT_EQ(6, timesTwo(3));}
int main(int argc, char* argv[]){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
The script compiles fine with CLANG (Apple clang version 11.0.3)
clang++ -std=c++17 -lgtest gt.cpp -o gt
but fails with GCC (g++ (GCC) 10.2.0)
g++ -std=c++17 -lgtest gt.cpp -o gt
gt.cpp:2:9: fatal error: gtest/gtest.h: No such file or directory
2 | #include<gtest/gtest.h>
|
Using the -H option in CLANG, I see the header file is included from /usr/local/include. Also, I can find the libgtest.a file in /usr/local/bin/. So, I did
g++ -std=c++17 gt.cpp -o gt -I/usr/local/include/ -L/usr/local/lib/ -lgtest
and got a long list of undefined symbols starting with
Macavity:test remi$ g++ -std=c++17 gt.cpp -o gt -I/usr/local/include/ -L/usr/local/lib/ -lgtest
Undefined symbols for architecture x86_64:
"__ZN7testing8internal9EqFailureEPKcS2_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_b", referenced from:
__ZN7testing8internal18CmpHelperEQFailureIidEENS_15AssertionResultEPKcS4_RKT_RKT0_ in ccrUwUPO.o
"__ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4findEcm", referenced from:
__ZN7testing8internal11SplitStringERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEcPNS1_6vectorIS7_NS5_IS7_EEEE in libgtest.a(gtest-all.cc.o)
__ZN7testing8internalL21FormatDeathTestOutputERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE in libgtest.a(gtest-all.cc.o)
"__ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7compareEmmPKcm", referenced from:
Can you help me figure out why GCC fails to compile here?
Here is this error message passed through a http://demangler.com/
Undefined symbols for architecture x86_64:
"_testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)", referenced from:
_testing::AssertionResult testing::internal::CmpHelperEQFailure<int, double>(char const*, char const*, int const&, double const&) in ccrUwUPO.o
"_std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char, unsigned long) const", referenced from:
_testing::internal::SplitString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*) in libgtest.a(gtest-all.cc.o)
_testing::internal::FormatDeathTestOutput(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libgtest.a(gtest-all.cc.o)
"_std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const", referenced from:
Note that second and third error complains that linker can't find implementation of: std::string::find(char, unsigned long) and std::string::compare(unsigned long, unsigned long, char const*, unsigned long) const.
Those are parts of standard C++ library. Since std::string is template some parts of it are part of library which uses that template, but is some cases it can be part of C++ runtime.
Now I suspect that you compiled gtest with a clang and try use it when building test with gcc (or vice versa). A bit different implementations of std::string on both compilers lead to divergence in available symbols.
So please make sure that gtest and test application are build with same compiler.
Here is some description of binary compatibility between gcc and clang. There are some hints what problem is, but it is not very formal (maybe I will find better document).

Why are these symbols not found?

I am trying to compile libopenshot on MacOS.
When I run the build I get the following error during linking:
→ make VERBOSE=1
...
/usr/local/bin/g++-4.9 -std=c++11 -g -ggdb -fopenmp -g -dynamiclib -Wl,-headerpad_max_install_names -compatibility_version 14.0.0 -current_version 0.1.9 -o libopenshot.0.1.9.dylib -install_name /source/libopenshot/build/src/libopenshot.14.dylib CMakeFiles/openshot.dir/AudioBufferSource.cpp.o CMakeFiles/openshot.dir/AudioReaderSource.cpp.o CMakeFiles/openshot.dir/AudioResampler.cpp.o CMakeFiles/openshot.dir/CacheBase.cpp.o CMakeFiles/openshot.dir/CacheDisk.cpp.o CMakeFiles/openshot.dir/CacheMemory.cpp.o CMakeFiles/openshot.dir/ChunkReader.cpp.o CMakeFiles/openshot.dir/ChunkWriter.cpp.o CMakeFiles/openshot.dir/Color.cpp.o CMakeFiles/openshot.dir/Clip.cpp.o CMakeFiles/openshot.dir/ClipBase.cpp.o CMakeFiles/openshot.dir/Coordinate.cpp.o CMakeFiles/openshot.dir/CrashHandler.cpp.o CMakeFiles/openshot.dir/DummyReader.cpp.o CMakeFiles/openshot.dir/ReaderBase.cpp.o CMakeFiles/openshot.dir/RendererBase.cpp.o CMakeFiles/openshot.dir/WriterBase.cpp.o CMakeFiles/openshot.dir/EffectBase.cpp.o CMakeFiles/openshot.dir/effects/Bars.cpp.o CMakeFiles/openshot.dir/effects/Blur.cpp.o CMakeFiles/openshot.dir/effects/Brightness.cpp.o CMakeFiles/openshot.dir/effects/ChromaKey.cpp.o CMakeFiles/openshot.dir/effects/ColorShift.cpp.o CMakeFiles/openshot.dir/effects/Crop.cpp.o CMakeFiles/openshot.dir/effects/Deinterlace.cpp.o CMakeFiles/openshot.dir/effects/Hue.cpp.o CMakeFiles/openshot.dir/effects/Mask.cpp.o CMakeFiles/openshot.dir/effects/Negate.cpp.o CMakeFiles/openshot.dir/effects/Pixelate.cpp.o CMakeFiles/openshot.dir/effects/Saturation.cpp.o CMakeFiles/openshot.dir/effects/Shift.cpp.o CMakeFiles/openshot.dir/effects/Wave.cpp.o CMakeFiles/openshot.dir/EffectInfo.cpp.o CMakeFiles/openshot.dir/FFmpegReader.cpp.o CMakeFiles/openshot.dir/FFmpegWriter.cpp.o CMakeFiles/openshot.dir/Fraction.cpp.o CMakeFiles/openshot.dir/Frame.cpp.o CMakeFiles/openshot.dir/FrameMapper.cpp.o CMakeFiles/openshot.dir/KeyFrame.cpp.o CMakeFiles/openshot.dir/ZmqLogger.cpp.o CMakeFiles/openshot.dir/PlayerBase.cpp.o CMakeFiles/openshot.dir/Point.cpp.o CMakeFiles/openshot.dir/Profiles.cpp.o CMakeFiles/openshot.dir/QtImageReader.cpp.o CMakeFiles/openshot.dir/QtPlayer.cpp.o CMakeFiles/openshot.dir/Timeline.cpp.o CMakeFiles/openshot.dir/Qt/AudioPlaybackThread.cpp.o CMakeFiles/openshot.dir/Qt/PlayerDemo.cpp.o CMakeFiles/openshot.dir/Qt/PlayerPrivate.cpp.o CMakeFiles/openshot.dir/Qt/VideoCacheThread.cpp.o CMakeFiles/openshot.dir/Qt/VideoPlaybackThread.cpp.o CMakeFiles/openshot.dir/Qt/VideoRenderWidget.cpp.o CMakeFiles/openshot.dir/Qt/VideoRenderer.cpp.o CMakeFiles/openshot.dir/__/include/Qt/moc_AudioPlaybackThread.cpp.o CMakeFiles/openshot.dir/__/include/Qt/moc_PlayerDemo.cpp.o CMakeFiles/openshot.dir/__/include/Qt/moc_PlayerPrivate.cpp.o CMakeFiles/openshot.dir/__/include/Qt/moc_VideoCacheThread.cpp.o CMakeFiles/openshot.dir/__/include/Qt/moc_VideoPlaybackThread.cpp.o CMakeFiles/openshot.dir/__/include/Qt/moc_VideoRenderWidget.cpp.o CMakeFiles/openshot.dir/__/include/Qt/moc_VideoRenderer.cpp.o CMakeFiles/openshot.dir/__/thirdparty/jsoncpp/src/lib_json/json_reader.cpp.o CMakeFiles/openshot.dir/__/thirdparty/jsoncpp/src/lib_json/json_value.cpp.o CMakeFiles/openshot.dir/__/thirdparty/jsoncpp/src/lib_json/json_writer.cpp.o CMakeFiles/openshot.dir/ImageReader.cpp.o CMakeFiles/openshot.dir/ImageWriter.cpp.o CMakeFiles/openshot.dir/TextReader.cpp.o /usr/local/opt/ffmpeg#2.8/lib/libavformat.dylib /usr/local/opt/ffmpeg#2.8/lib/libavcodec.dylib /usr/local/opt/ffmpeg#2.8/lib/libavutil.dylib /usr/local/opt/ffmpeg#2.8/lib/libavdevice.dylib /usr/local/opt/ffmpeg#2.8/lib/libswscale.dylib /usr/local/opt/ffmpeg#2.8/lib/libavresample.dylib /usr/local/lib/libopenshot-audio.dylib /usr/local/Cellar/qt/5.9.0/lib/QtMultimediaWidgets.framework/QtMultimediaWidgets /usr/local/lib/libzmq.dylib -fopenmp /usr/local/opt/imagemagick#6/lib/libMagick++-6.Q16.dylib /usr/local/opt/imagemagick#6/lib/libMagickWand-6.Q16.dylib /usr/local/opt/imagemagick#6/lib/libMagickCore-6.Q16.dylib /usr/local/Cellar/qt/5.9.0/lib/QtWidgets.framework/QtWidgets /usr/local/Cellar/qt/5.9.0/lib/QtMultimedia.framework/QtMultimedia /usr/local/Cellar/qt/5.9.0/lib/QtGui.framework/QtGui /usr/local/Cellar/qt/5.9.0/lib/QtNetwork.framework/QtNetwork /usr/local/Cellar/qt/5.9.0/lib/QtCore.framework/QtCore
Undefined symbols for architecture x86_64:
"Magick::DrawableFont::DrawableFont(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
openshot::TextReader::Open() in TextReader.cpp.o
"Magick::DrawableText::DrawableText(double, double, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
openshot::TextReader::Open() in TextReader.cpp.o
"Magick::Color::Color(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
openshot::TextReader::Open() in TextReader.cpp.o
"Magick::Image::draw(std::list<Magick::Drawable, std::allocator<Magick::Drawable> > const&)", referenced from:
openshot::TextReader::Open() in TextReader.cpp.o
"Magick::Image::magick(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
openshot::ImageWriter::WriteFrame(std::shared_ptr<openshot::Frame>) in ImageWriter.cpp.o
"Magick::Image::Image(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
openshot::ImageReader::Open() in ImageReader.cpp.o
"Magick::Image::Image(unsigned long, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, MagickCore::StorageType, void const*)", referenced from:
openshot::Frame::GetMagickImage() in Frame.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [src/libopenshot.0.1.9.dylib] Error 1
make[1]: *** [src/CMakeFiles/openshot.dir/all] Error 2
make: *** [all] Error 2
It looks like the compiler can find it:
→ make TextReader.i && grep DrawableFont CMakeFiles/openshot.dir/TextReader.cpp.i
Preprocessing CXX source to CMakeFiles/openshot.dir/TextReader.cpp.i
class __attribute__ ((visibility ("default"))) DrawableFont : public DrawableBase
DrawableFont ( const std::string &font_ );
DrawableFont ( const std::string &family_,
DrawableFont ( const DrawableFont& original_ );
~DrawableFont ( void );
lines.push_back(Magick::DrawableFont(font));
I can't figure out why the linker doesn't find these symbols. I don't know how to read the symbol table but it looks like they might be in the library.
→ nm -arch x86_64 -gU /usr/local/opt/imagemagick#6/lib/libMagick++-6.Q16.dylib | grep DrawableFont
0000000000009780 T __ZN6Magick12DrawableFontC1ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE
0000000000009842 T __ZN6Magick12DrawableFontC1ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEN10MagickCore9StyleTypeEjNSA_11StretchTypeE
00000000000098c2 T __ZN6Magick12DrawableFontC1ERKS0_
0000000000009736 T __ZN6Magick12DrawableFontC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE
00000000000097ca T __ZN6Magick12DrawableFontC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEN10MagickCore9StyleTypeEjNSA_11StretchTypeE
000000000000984c T __ZN6Magick12DrawableFontC2ERKS0_
0000000000009914 T __ZN6Magick12DrawableFontD0Ev
000000000000990a T __ZN6Magick12DrawableFontD1Ev
00000000000098cc T __ZN6Magick12DrawableFontD2Ev
00000000000099e0 T __ZNK6Magick12DrawableFont4copyEv
0000000000009942 T __ZNK6Magick12DrawableFontclEPN10MagickCore12_DrawingWandE
000000000002e230 S __ZTIN6Magick12DrawableFontE
00000000000298b0 S __ZTSN6Magick12DrawableFontE
000000000002d060 S __ZTVN6Magick12DrawableFontE
Any idea what might be wrong or what else I should try to diagnose this error?
Since C++11 the ABI (Application Binary Interface) has changed. This means that if some of your dependencies are compiled using C++98 compatibility and others using a compatibility superior or equal C++11, the resolution of symbol names might not always be the same.
Therefore, your linker is trying to link a same symbol with different name.
Solution: re-compiling all dependencies with the same compatible ABI. In your case, you should just recompile everything with -std=c++11 flag.

c++ boost 1_46_1 on OSX 10.6.6. not linking

i downloaded c++ boost 1_46_1. unzipped it and followed the installation instructions.
i have tried to get a basic boost program to compile and link, but with no luck so far.
here it the boost program
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <iostream>
#include <iterator>
using namespace std;
int main(int ac, char* av[])
{
try {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
if (vm.count("compression")) {
cout << "Compression level was set to "
<< vm["compression"].as<int>() << ".\n";
} else {
cout << "Compression level was not set.\n";
}
}
catch(exception& e) {
cerr << "error: " << e.what() << "\n";
return 1;
}
catch(...) {
cerr << "Exception of unknown type!\n";
}
return 0;
}
here is my makefile
# compiler to use
CC = c++
INC = -I ~/usr/local/boost_1_46_1
#-I /usr/include/c++/4.2.1
LIB=-L~/usr/local/boost_1_46_1/stage/lib
#LIB =-Lusr/local/lib
#LIBNAME =-libboost_program_options.dylib
SOURCE = main.cpp
OUTPUT = out
all:
$(CC) $(INC) $(SOURCE) -o $(OUTPUT) -v $(LIB) -dynamic
here is the error i get
Using built-in specs. Target: i686-apple-darwin10 Configured with: /var/tmp/gcc/gcc-5664~89/src/configure
--disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/
--with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1 Thread model: posix gcc version 4.2.1 (Apple Inc. build 5664) /usr/libexec/gcc/i686-apple-darwin10/4.2.1/cc1plus
-quiet -v -I /Users/smith/usr/local/boost_1_46_1
-imultilib x86_64 -D__DYNAMIC__ main.cpp -fPIC -quiet -dumpbase main.cpp -mmacosx-version-min=10.6.6
-m64 -mtune=core2 -auxbase main -version -D__private_extern__=extern -o /var/folders/y7/y7wCKCc3HJWLBAK5YLrg5E+++TI/-Tmp-//ccumV5Oo.s ignoring nonexistent directory "/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../../i686-apple-darwin10/include" ignoring nonexistent directory "/Users/smith/usr/local/boost_1_46_1"
#include "..." search starts here:
#include <...> search starts here: /usr/include/c++/4.2.1 /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64 /usr/include/c++/4.2.1/backward /usr/local/include /usr/lib/gcc/i686-apple-darwin10/4.2.1/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. GNU C++ version 4.2.1 (Apple Inc. build 5664) (i686-apple-darwin10) compiled by GNU C version 4.2.1 (Apple Inc. build 5664). GGC heuristics: --param ggc-min-expand=150
--param ggc-min-heapsize=131072 Compiler executable checksum: 35e7c8ac2c3562481c35a1833320fc34 /usr/libexec/gcc/i686-apple-darwin10/4.2.1/as
-arch x86_64 -force_cpusubtype_ALL -o /var/folders/y7/y7wCKCc3HJWLBAK5YLrg5E+++TI/-Tmp-//cce6AA55.o /var/folders/y7/y7wCKCc3HJWLBAK5YLrg5E+++TI/-Tmp-//ccumV5Oo.s /usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2
-dynamic -arch x86_64 -dynamic -macosx_version_min 10.6.6 -weak_reference_mismatches non-weak -o out -lcrt1.10.6.o
-L~/usr/local/boost_1_46_1/stage/lib -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64
-L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1
-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/folders/y7/y7wCKCc3HJWLBAK5YLrg5E+++TI/-Tmp-//cce6AA55.o
-lstdc++ -lSystem -lgcc -lSystem ld: warning: directory '~/usr/local/boost_1_46_1/stage/lib' following -L not found Undefined symbols: "boost::program_options::operator<<(std::basic_ostream<char, std::char_traits<char> >&, boost::program_options::options_description const&)", referenced from:
_main in cce6AA55.o "vtable for boost::program_options::variables_map", referenced from:
boost::program_options::variables_map::~variables_map()in cce6AA55.o "boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>)", referenced from:
boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>)in cce6AA55.o "typeinfo for boost::program_options::validation_error", referenced from:
typeinfo for boost::exception_detail::error_info_injector<boost::program_options::validation_error>in cce6AA55.o
typeinfo for boost::program_options::invalid_option_valuein cce6AA55.o "boost::program_options::detail::cmdline::cmdline(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)", referenced from:
boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)in cce6AA55.o "boost::program_options::options_description_easy_init::operator()(char const*, char const*)", referenced from:
_main in cce6AA55.o "boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const", referenced from:
vtable for boost::program_options::typed_value<int, char>in cce6AA55.o "boost::program_options::detail::cmdline::style(int)", referenced from:
boost::program_options::basic_command_line_parser<char>::style(int)in cce6AA55.o "boost::program_options::to_internal(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > boost::program_options::to_internal<std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)in cce6AA55.o "boost::program_options::notify(boost::program_options::variables_map&)", referenced from:
_main in cce6AA55.o "boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)", referenced from:
_main in cce6AA55.o "boost::program_options::store(boost::program_options::basic_parsed_options<char> const&, boost::program_options::variables_map&, bool)", referenced from:
_main in cce6AA55.o "boost::program_options::arg", referenced from:
boost::program_options::typed_value<int, char>::name() constin cce6AA55.o
boost::program_options::typed_value<int, char>::name() constin cce6AA55.o "vtable for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
boost::program_options::value_semantic_codecvt_helper<char>::value_semantic_codecvt_helper()in cce6AA55.o
boost::program_options::value_semantic_codecvt_helper<char>::~value_semantic_codecvt_helper()in cce6AA55.o "typeinfo for boost::program_options::value_semantic_codecvt_helper<char>", referenced from:
typeinfo for boost::program_options::typed_value<int, char>in cce6AA55.o "boost::program_options::options_description::add_options()", referenced from:
_main in cce6AA55.o "boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
std::basic_string<char, std::char_traits<char>, std::allocator<char> > const& boost::program_options::validators::get_single_string<char>(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)in cce6AA55.o
std::basic_string<char, std::char_traits<char>, std::allocator<char> > const& boost::program_options::validators::get_single_string<char>(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool)in cce6AA55.o "vtable for boost::program_options::validation_error", referenced from:
boost::program_options::validation_error::~validation_error()in cce6AA55.o
boost::program_options::validation_error::~validation_error()in cce6AA55.o
boost::program_options::validation_error::validation_error(boost::program_options::validation_error const&)in cce6AA55.o "boost::program_options::validation_error::what() const", referenced from:
vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error>in cce6AA55.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error>
>in cce6AA55.o
vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value>in cce6AA55.o
vtable for boost::program_options::invalid_option_valuein cce6AA55.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value>
>in cce6AA55.o "boost::program_options::variables_map::variables_map()", referenced from:
_main in cce6AA55.o "boost::program_options::options_description::options_description(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)", referenced from:
_main in cce6AA55.o "boost::program_options::detail::cmdline::run()", referenced from:
boost::program_options::basic_command_line_parser<char>::run() in cce6AA55.o "boost::program_options::invalid_option_value::invalid_option_value(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
void boost::program_options::validate<int, char>(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, int*, long)in cce6AA55.o "boost::program_options::options_description::m_default_line_length", referenced from:
_main in cce6AA55.o
_main in cce6AA55.o "boost::program_options::detail::cmdline::set_options_description(boost::program_options::options_description const&)", referenced from:
boost::program_options::basic_command_line_parser<char>::options(boost::program_options::options_description const&)in cce6AA55.o "boost::program_options::validators::check_first_occurrence(boost::any const&)", referenced from:
void boost::program_options::validate<int, char>(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, int*, long)in cce6AA55.o "boost::program_options::abstract_variables_map::operator[](std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const", referenced from:
boost::program_options::variables_map::operator[](std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) constin cce6AA55.o ld: symbol(s) not found collect2: ld returned 1 exit status make: *** [all] Error 1
You lack -lboost_program_options
all:
$(CC) $(INC) $(SOURCE) -o $(OUTPUT) $(LIB) -lboost_program_options -dynamic
you are providing linker with wrong path:
warning: directory '~/usr/local/boost_1_46_1/stage/lib' following -L not found
results in not linking your objects
The linker output includes the line:
ignoring nonexistent directory "/Users/smith/usr/local/boost_1_46_1"
so there is some mismatch between where you expect the libraries to be and where they actually are...