Closed luav closed 6 years ago
All build files (build.bfg
, build/build.ninja
) use c++
as a compiler, which is g++
. Then I don't understand why the libmettle
is successfully linked from clang++
but not from g++
(which is used to build the library itself).
The library itself is built fine and had the symbolds that can't be found by g++:
$ nm -gC /usr/local/lib/libmettle.so | grep drive_tests
000000000018d675 T mettle::detail::drive_tests(int, char const**, std::vector<mettle::compiled_suite<mettle::test_result ()>, std::allocator<mettle::compiled_suite<mettle::test_result ()> > > const&)
With GCC (and often with other CC-like compilers), library files should be specified after the object (or source) files that require a symbol from the library. This should work:
g++ -std=c++14 -o test_01_basic test_01_basic.cpp -lmettle
I'm actually a little surprised that it works under clang.
@jimporter thaks a lot! It works! It would be nice to update the example in the tutorial to match any compiler (https://jimporter.github.io/mettle/tutorial/#building-the-test):
$ clang++ -std=c++14 -lmettle -o test_first test_first.cpp
to
$ c++ -std=c++14 -o test_first test_first.cpp -lmettle
PS I have a similar error in the CodeBlocks IDE but the order of linking there seems to be correct, which is weird:
g++ -Wnon-virtual-dtor -Winit-self -Wcast-align -Wundef -Wunreachable-code -Wmissing-include-dirs -Weffc++ -Wzero-as-null-pointer-constant -std=c++14 -fexceptions -fstack-protector-strong -DREVISION=1156/49969180201c -D_FORTIFY_SOURCE=2 -DFTRACE_GLOBAL -DMEMBERSHARE_BYCANDS -DINTEROVP_LINKS -DNOPREFILTER -DGESTCHAINS_MCANDS -DDYNAMIC_GAMMA -DMCCHAINS_RANKED -Wredundant-decls -Winline -Wswitch-default -Wmain -Wall -g -Wsuggest-final-types -Wsuggest-final-methods -DDEBUG -D_GLIBCXX_DEBUG -DTRACE=2 -DVALIDATE=2 -DUTEST -Wnon-virtual-dtor -Wredundant-decls -Wundef -Wunreachable-code -Wmissing-include-dirs -Weffc++ -Wzero-as-null-pointer-constant -std=c++14 -Iexport -Iinclude -Iexport/shared -Iimport -c /media/truecrypt1/projects/clustering/daoc/lib/tests/test_01_basic.cpp -o obj/Debug/tests/test_01_basic.o
g++ -L/usr/local/lib -o "bin/Debug/TestBasic" obj/Debug/tests/test_01_basic.o -lstdc++fs -lmettle
obj/Debug/tests/test_01_basic.o: In function `main':
/usr/local/include/mettle/driver/lib_driver.hpp:18: undefined reference to `mettle::detail::drive_tests(int, char const**, std::__debug::vector<mettle::compiled_suite<mettle::test_result ()>, std::allocator<mettle::compiled_suite<mettle::test_result ()> > > const&)'
collect2: error: ld returned 1 exit status
It would be nice to update the example in the tutorial to match any compiler (https://jimporter.github.io/mettle/tutorial/#building-the-test)
Whooooops! Fixed.
As for the CodeBlocks thing, I'm not sure what the issue is there, but maybe you need to swap -lstdc++fs
and -lmettle
? Or maybe one of the compilation options is doing something weird? I'm not familiar with all of them and maybe one of them is affecting the ABI. (For example, some of your -Iwhatever
options might be causing GCC to load a different version of the C++ standard library and that's causing an ABI incompatibility. That's just a guess though.)
Thank you for the hints, I will fight with the IDE :-)
It was -D_GLIBCXX_DEBUG
Ah yeah, that would probably do it. Good to see it's working now!
Majority of linux-es use
g++
as default system compiler (c++
) and default build ofmettle
refuses to be linked from the binaries built withc++
(g++
):But
clang++
binaries linklibmettle
fine:Probably, it makes sense to perform default
mettle
build using default system compiler instead ofclang++
.