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.
Related
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).
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.
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.
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
I'm trying to get some sample code to work happily with OpenMS and running into a great deal of trouble. I have (just a small sample program that shipped as an example):
#include <OpenMS/FILTERING/SMOOTHING/GaussFilter.h>
#include <OpenMS/FORMAT/MzMLFile.h>
#include <OpenMS/KERNEL/StandardTypes.h>
#include <stdio.h>
using namespace OpenMS;
using namespace std;
Int main(){
PeakMap exp;
MzMLFile mzdata_file;
mzdata_file.load("../sampledata_Centroidmode.mzML",exp);
GaussFilter g;
Param param;
param.setValue("gaussian_width",1.0);
g.setParameters(param);
g.filterExperiment(exp);
return 0;
}
And I compile it:
g++ -Wall -IOpenMS-1.7.0/include -IOpenMS-1.7.0/contrib/include -I/Library/Frameworks/QtCore.framework/Headers -arch i386 scratch.cpp
It comes up with a boatload of errors (about ~500Kb of them, actually). The problem seems to lie in "using namespace OpenMS;" A small sample of the errors:
Undefined symbols:
"OpenMS::DataValue::DataValue(int)", referenced from:
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::handleUserParam_(OpenMS::String const&, OpenMS::String const&, OpenMS::String const&, OpenMS::String const&, OpenMS::String const&)in cc7cSzjW.o
"OpenMS::DataValue::DataValue()", referenced from:
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::handleUserParam_(OpenMS::String const&, OpenMS::String const&, OpenMS::String const&, OpenMS::String const&, OpenMS::String const&)in cc7cSzjW.o
"OpenMS::SourceFile::operator!=(OpenMS::SourceFile const&) const", referenced from:
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::writeTo(std::basic_ostream<char, std::char_traits<char> >&)in cc7cSzjW.o
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::writeTo(std::basic_ostream<char, std::char_traits<char> >&)in cc7cSzjW.o
OpenMS::Internal::MzMLHandler<OpenMS::MSExperiment<OpenMS::Peak1D, OpenMS::ChromatogramPeak> >::writeTo(std::basic_ostream<char, std::char_traits<char> >&)in cc7cSzjW.o
...
ld: symbol(s) not found
collect2: ld returned 1 exit status
Does anyone have insight as to what I'm not doing right?
Try compiling it to an object file (-c) and see if the problems still occur. E..g.: Is this a compiling issue or a linking issue?
Also: Should there be a -L flag to search a particular library path? Should there be a -l flag to link in a particular library?