Closed blshkv closed 5 years ago
The full log is 1M, uploaded in two parts here: https://gist.github.com/blshkv/7f986646214fdeb8ca6c0f98309ce5d6 https://gist.github.com/blshkv/034704924e21cd09420f46e7b560dfe5
https://gcc.gnu.org/wiki/Cxx11AbiCompatibility https://stackoverflow.com/questions/33394934/converting-std-cxx11string-to-stdstring
So what would be a workaround / solution?
Do you use cmake to compile LIEF ?
Yes
from the provided logs: https://gist.github.com/blshkv/7f986646214fdeb8ca6c0f98309ce5d6#file-build-log-L19
The issue is much deeper and related to gcc ABI compatibility.
Actually LIEF requires C++11
and compilation is ok on:
If you manage to understand why it fails, I would be glad to integrate your fix
Ok, this is messy. CMakeLists.txt
has the following initial setting:
set_property(TARGET LIB_LIEF PROPERTY CXX_STANDARD 11)
but later it changes to:
if (LIEF_SUPPORT_CXX14)
target_compile_features(LIB_LIEF PRIVATE cxx_std_14)
api/python is also choose cxx_std_14
if it's available
However, everything else is getting compiled with CXX_STANDARD 11
Hi, I'm also getting undefined reference to LIEF::ELF::Parser::parse as well as undefined reference to LIEF::ELF::Binary::get_section.
I downloaded version 0.9.0 for Linux from here and I'm using the recommended CMake find_package integration from here.
My project is using C++17.
Is there anything I'm doing wrong or any way I can get this working?
Did you link against the static library or the shared one ?
I've tried both with the same result.
I'm trying to build my project as a shared library.
Could you share minimal project to reproduce it ?
I had a look into this and it seems that when I build my project as a library there are no issues. It is only when I try to link against my library.
I've tried to create a minimal project: LIEF-minimal-example.zip
I've assumed that LIEF will be in a folder in the same directory called 'LIEF-0.9.0-Linux' but this can be changed using the -DLIEF_ROOT flag as shown in the CMake example
OK I can reproduce the problem. It weird because clang 8
seems to correctly export the symbol but GCC don't. This commit https://github.com/lief-project/LIEF/commit/35805fb598a0a737135eeae8ed60dd019f0b05af should fix it
still unable to compile examples, it fails similarly:
[621/641] : && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/elf_builder.dir/elf_builder.cpp.o -o examples/cpp/elf_builder -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190504/work/lief-0.9.0_p20190504_build libLIEF.so && :
FAILED: examples/cpp/elf_builder
: && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/elf_builder.dir/elf_builder.cpp.o -o examples/cpp/elf_builder -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190504/work/lief-0.9.0_p20190504_build libLIEF.so && :
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/elf_builder.dir/elf_builder.cpp.o: in function `main':
elf_builder.cpp:(.text.startup+0x68): undefined reference to `LIEF::ELF::Parser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, LIEF::ELF::DYNSYM_COUNT_METHODS)'
collect2: error: ld returned 1 exit status
[622/641] : && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/elf_reader.dir/elf_reader.cpp.o -o examples/cpp/elf_reader -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190504/work/lief-0.9.0_p20190504_build libLIEF.so && :
FAILED: examples/cpp/elf_reader
: && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/elf_reader.dir/elf_reader.cpp.o -o examples/cpp/elf_reader -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190504/work/lief-0.9.0_p20190504_build libLIEF.so && :
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/elf_reader.dir/elf_reader.cpp.o: in function `main':
elf_reader.cpp:(.text.startup+0x23): undefined reference to `LIEF::Logger::set_level(LIEF::LOGGING_LEVEL)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: elf_reader.cpp:(.text.startup+0x101): undefined reference to `LIEF::ELF::Parser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, LIEF::ELF::DYNSYM_COUNT_METHODS)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: elf_reader.cpp:(.text.startup+0x126): undefined reference to `LIEF::ELF::Binary::functions() const'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/elf_reader.dir/elf_reader.cpp.o:(.data.rel.local.DW.ref._ZTIN4LIEF9exceptionE[DW.ref._ZTIN4LIEF9exceptionE]+0x0): undefined reference to `typeinfo for LIEF::exception'
collect2: error: ld returned 1 exit status
[623/641] : && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o -o examples/cpp/dex_reader -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190504/work/lief-0.9.0_p20190504_build libLIEF.so && :
FAILED: examples/cpp/dex_reader
: && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o -o examples/cpp/dex_reader -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190504/work/lief-0.9.0_p20190504_build libLIEF.so && :
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o: in function `main':
dex_reader.cpp:(.text.startup+0x23): undefined reference to `LIEF::Logger::set_level(LIEF::LOGGING_LEVEL)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: dex_reader.cpp:(.text.startup+0xf5): undefined reference to `LIEF::DEX::Parser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o:(.data.rel.local.DW.ref._ZTIN4LIEF9exceptionE[DW.ref._ZTIN4LIEF9exceptionE]+0x0): undefined reference to `typeinfo for LIEF::exception'
collect2: error: ld returned 1 exit status
After further investigation the root cause seems to be GLIBCXX_USE_CXX11_ABI
that is set to 0 on CI. It produces std::string
symbols instead of std::__cxx11::basic_string<...>
@ScottEgerton I checked with the nightly package: https://lief-project.github.io/packages/sdk/ and it works. @blshkv Could you also check we new packages ?
nop, did not help
Thanks for looking into this. I just tried the nightly package and it links successfully for me now.
can you give me a hint how to apply the same fix for the latest git? The current fix (https://github.com/lief-project/LIEF/commit/27a03a6fd3169f427fb950293f0863dcd50ac710) did not work for me
btw, out of curiosity, I have changed the line https://github.com/lief-project/LIEF/blob/master/CMakeLists.txt#L158 to cxx_std_11
to make sure that everything is compiled with one API and got a new error. Perhaps, everything should be compiled with CXX14 then?
The error is:
>>> Working in BUILD_DIR: "/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/lief-0.9.0_p20190505_build"
ninja -v -j4 -l0
[1/230] /usr/bin/x86_64-pc-linux-gnu-g++ -DELPP_DISABLE_DEFAULT_CRASH_HANDLING -DELPP_HANDLE_SIGABRT=0 -DELPP_NO_DEFAULT_LOG_FILE -DLIB_LIEF_EXPORTS -DLIEF_STATIC -DVDEBUG=9 -D_GLIBCXX_USE_CXX11_ABI=1 -Ilief_libjson-prefix/src/lief_libjson -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/include -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/api/c/include -Iinclude -Ilief_frozen-prefix/src/lief_frozen/include -Ilief_rang_cpp_color-prefix/src/lief_rang_cpp_color/include -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/src -I. -Ilief_easyloggingpp-prefix/src/lief_easyloggingpp/src -Imbed_tls/src/lief_mbed_tls/include -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/include/LIEF -march=native -O2 -pipe -frecord-gcc-switches -fPIC -fvisibility=hidden -Wall -Wextra -Wpedantic -fno-stack-protector -fomit-frame-pointer -fno-strict-aliasing -fexceptions -fvisibility=hidden -Wno-expansion-to-defined -fdiagnostics-color=always -std=gnu++11 -MD -MT CMakeFiles/LIB_LIEF.dir/src/Abstract/EnumToString.cpp.o -MF CMakeFiles/LIB_LIEF.dir/src/Abstract/EnumToString.cpp.o.d -o CMakeFiles/LIB_LIEF.dir/src/Abstract/EnumToString.cpp.o -c /var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/src/Abstract/EnumToString.cpp
FAILED: CMakeFiles/LIB_LIEF.dir/src/Abstract/EnumToString.cpp.o
/usr/bin/x86_64-pc-linux-gnu-g++ -DELPP_DISABLE_DEFAULT_CRASH_HANDLING -DELPP_HANDLE_SIGABRT=0 -DELPP_NO_DEFAULT_LOG_FILE -DLIB_LIEF_EXPORTS -DLIEF_STATIC -DVDEBUG=9 -D_GLIBCXX_USE_CXX11_ABI=1 -Ilief_libjson-prefix/src/lief_libjson -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/include -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/api/c/include -Iinclude -Ilief_frozen-prefix/src/lief_frozen/include -Ilief_rang_cpp_color-prefix/src/lief_rang_cpp_color/include -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/src -I. -Ilief_easyloggingpp-prefix/src/lief_easyloggingpp/src -Imbed_tls/src/lief_mbed_tls/include -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/include/LIEF -march=native -O2 -pipe -frecord-gcc-switches -fPIC -fvisibility=hidden -Wall -Wextra -Wpedantic -fno-stack-protector -fomit-frame-pointer -fno-strict-aliasing -fexceptions -fvisibility=hidden -Wno-expansion-to-defined -fdiagnostics-color=always -std=gnu++11 -MD -MT CMakeFiles/LIB_LIEF.dir/src/Abstract/EnumToString.cpp.o -MF CMakeFiles/LIB_LIEF.dir/src/Abstract/EnumToString.cpp.o.d -o CMakeFiles/LIB_LIEF.dir/src/Abstract/EnumToString.cpp.o -c /var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/src/Abstract/EnumToString.cpp
In file included from lief_frozen-prefix/src/lief_frozen/include/frozen/bits/algorithms.h:26,
from lief_frozen-prefix/src/lief_frozen/include/frozen/map.h:28,
from /var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/src/frozen.hpp:22,
from /var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/src/Abstract/EnumToString.cpp:17:
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:69:29: error: ‘constexpr const value_type& frozen::bits::cvector<T, N>::operator[](std::size_t) const’ cannot be overloaded with ‘constexpr frozen::bits::cvector<T, N>::value_type& frozen::bits::cvector<T, N>::operator[](std::size_t) const’
constexpr const_reference operator[](std::size_t index) const { return data[index]; }
^~~~~~~~
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:68:29: note: previous declaration ‘constexpr frozen::bits::cvector<T, N>::value_type& frozen::bits::cvector<T, N>::operator[](std::size_t) const’
constexpr reference operator[](std::size_t index) { return data[index]; }
^~~~~~~~
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:72:29: error: ‘constexpr const value_type& frozen::bits::cvector<T, N>::back() const’ cannot be overloaded with ‘constexpr frozen::bits::cvector<T, N>::value_type& frozen::bits::cvector<T, N>::back() const’
constexpr const_reference back() const { return data[dsize - 1]; }
^~~~
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:71:29: note: previous declaration ‘constexpr frozen::bits::cvector<T, N>::value_type& frozen::bits::cvector<T, N>::back() const’
constexpr reference back() { return data[dsize - 1]; }
^~~~
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h: In constructor ‘frozen::bits::cvector<T, N>::cvector(frozen::bits::cvector<T, N>::size_type, const T&)’:
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:58:3: error: ‘constexpr’ constructor does not have empty body
}
^
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h: In member function ‘constexpr void frozen::bits::cvector<T, N>::push_back(const T&) const’:
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:75:53: error: increment of read-only location ‘((const frozen::bits::cvector<T, N>*)this)->frozen::bits::cvector<T, N>::dsize’
constexpr void push_back(const T & a) { data[dsize++] = a; }
^~
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h: In member function ‘constexpr void frozen::bits::cvector<T, N>::push_back(T&&) const’:
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:76:48: error: increment of read-only location ‘((const frozen::bits::cvector<T, N>*)this)->frozen::bits::cvector<T, N>::dsize’
constexpr void push_back(T && a) { data[dsize++] = std::move(a); }
^~
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h: In member function ‘constexpr void frozen::bits::cvector<T, N>::pop_back() const’:
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:77:33: error: decrement of read-only location ‘((const frozen::bits::cvector<T, N>*)this)->frozen::bits::cvector<T, N>::dsize’
constexpr void pop_back() { --dsize; }
^~~~~
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h: At global scope:
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:87:45: error: ‘std::index_sequence’ has not been declared
constexpr carray(T const (&init)[M], std::index_sequence<I...>)
^~~~~~~~~~~~~~
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:87:59: error: expected ‘,’ or ‘...’ before ‘<’ token
constexpr carray(T const (&init)[M], std::index_sequence<I...>)
^
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:90:36: error: ‘std::index_sequence’ has not been declared
constexpr carray(Iter iter, std::index_sequence<I...>)
^~~~~~~~~~~~~~
lief_frozen-prefix/src/lief_frozen/include/frozen/bits/basic_types.h:90:50: error: expected ‘,’ or ‘...’ before ‘<’ token
constexpr carray(Iter iter, std::index_sequence<I...>)
<skip>
can you give me a hint how to apply the same fix for the latest git? The current fix (27a03a6) did not work for me
I think you have issue with your own build system
btw, out of curiosity, I have changed the line https://github.com/lief-project/LIEF/blob/master/CMakeLists.txt#L158 to cxx_std_11 to make sure that everything is compiled with one API and got a new error. Perhaps, everything should be compiled with CXX14 then?
Nop, If the compiler supports C++14 then LIEF uses some features of C++14 otherwise it uses C++11. But the public API (i.e: include/LIEF/*.hpp) is compatible with C++11 standard
My build system is fine, and just upgraded the compiler to sys-devel/gcc-8.3.0-r1.
I can also build the provided SDK: share/LIEF/examples/cmake/external_project/build
perfectly fine as well.
However, I'm unable to build from the latest git. Perhaps, you can try to run the same commands?
Please re-open the issue as it is not fixed completely.
I can also build the provided SDK: share/LIEF/examples/cmake/external_project/build perfectly fine as well. ... However, I'm unable to build from the latest git. Perhaps, you can try to run the same commands?
Don't really understand the problem. What's the issue ? (C++14 ? / Undef symbol ? )
here is the updated log (the error is similar):
[453/641] /usr/bin/x86_64-pc-linux-gnu-g++ -DELPP_DISABLE_DEFAULT_CRASH_HANDLING -DELPP_HANDLE_SIGABRT=0 -DELPP_NO_DEFAULT_LOG_FILE -DVDEBUG=9 -D_GLIBCXX_USE_CXX11_ABI=1 -Ilief_libjson-prefix/src/lief_libjson -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/include -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/api/c/include -Iinclude -march=native -O2 -pipe -frecord-gcc-switches -std=gnu++11 -MD -MT examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o -MF examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o.d -o examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o -c /var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/examples/cpp/dex_reader.cpp
...
[462/641] /usr/bin/x86_64-pc-linux-gnu-g++ -DELPP_DISABLE_DEFAULT_CRASH_HANDLING -DELPP_HANDLE_SIGABRT=0 -DELPP_NO_DEFAULT_LOG_FILE -DVDEBUG=9 -D_GLIBCXX_USE_CXX11_ABI=1 -Ilief_libjson-prefix/src/lief_libjson -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/include -I/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/api/c/include -Iinclude -march=native -O2 -pipe -frecord-gcc-switches -std=gnu++11 -MD -MT examples/cpp/CMakeFiles/vdex_reader.dir/vdex_reader.cpp.o -MF examples/cpp/CMakeFiles/vdex_reader.dir/vdex_reader.cpp.o.d -o examples/cpp/CMakeFiles/vdex_reader.dir/vdex_reader.cpp.o -c /var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/LIEF-27a03a6fd3169f427fb950293f0863dcd50ac710/examples/cpp/vdex_reader.cpp
...
[621/641] : && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o -o examples/cpp/dex_reader -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/lief-0.9.0_p20190505_build libLIEF.so && :
FAILED: examples/cpp/dex_reader
: && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o -o examples/cpp/dex_reader -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/lief-0.9.0_p20190505_build libLIEF.so && :
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o: in function `main':
dex_reader.cpp:(.text.startup+0x23): undefined reference to `LIEF::Logger::set_level(LIEF::LOGGING_LEVEL)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: dex_reader.cpp:(.text.startup+0xf5): undefined reference to `LIEF::DEX::Parser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o:(.data.rel.local.DW.ref._ZTIN4LIEF9exceptionE[DW.ref._ZTIN4LIEF9exceptionE]+0x0): undefined reference to `typeinfo for LIEF::exception'
collect2: error: ld returned 1 exit status
[622/641] : && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/elf_reader.dir/elf_reader.cpp.o -o examples/cpp/elf_reader -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/lief-0.9.0_p20190505_build libLIEF.so && :
FAILED: examples/cpp/elf_reader
: && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/elf_reader.dir/elf_reader.cpp.o -o examples/cpp/elf_reader -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/lief-0.9.0_p20190505_build libLIEF.so && :
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/elf_reader.dir/elf_reader.cpp.o: in function `main':
elf_reader.cpp:(.text.startup+0x23): undefined reference to `LIEF::Logger::set_level(LIEF::LOGGING_LEVEL)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: elf_reader.cpp:(.text.startup+0x101): undefined reference to `LIEF::ELF::Parser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, LIEF::ELF::DYNSYM_COUNT_METHODS)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: elf_reader.cpp:(.text.startup+0x126): undefined reference to `LIEF::ELF::Binary::functions() const'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/elf_reader.dir/elf_reader.cpp.o:(.data.rel.local.DW.ref._ZTIN4LIEF9exceptionE[DW.ref._ZTIN4LIEF9exceptionE]+0x0): undefined reference to `typeinfo for LIEF::exception'
collect2: error: ld returned 1 exit status
[623/641] : && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/elf_builder.dir/elf_builder.cpp.o -o examples/cpp/elf_builder -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/lief-0.9.0_p20190505_build libLIEF.so && :
FAILED: examples/cpp/elf_builder
: && /usr/bin/x86_64-pc-linux-gnu-g++ -march=native -O2 -pipe -frecord-gcc-switches -Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 examples/cpp/CMakeFiles/elf_builder.dir/elf_builder.cpp.o -o examples/cpp/elf_builder -Wl,-rpath,/var/tmp/portage/dev-util/lief-0.9.0_p20190505/work/lief-0.9.0_p20190505_build libLIEF.so && :
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: examples/cpp/CMakeFiles/elf_builder.dir/elf_builder.cpp.o: in function `main':
elf_builder.cpp:(.text.startup+0x68): undefined reference to `LIEF::ELF::Parser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, LIEF::ELF::DYNSYM_COUNT_METHODS)'
collect2: error: ld returned 1 exit status
I have no idea what is going on, but you can see that it is getting compiled (in 453) with your fixes (-D_GLIBCXX_USE_CXX11_ABI=1 and -std=gnu++11) but it fails later:
undefined reference to `LIEF::Logger::set_level(LIEF::LOGGING_LEVEL)
and
undefined reference to `LIEF::ELF::Parser::parse(std::__cxx11::basic_string
skip
Sorry but I won't spent more time on this issue as I can't reproduce it and it looks specific to Gentoo. Feel free to do a PR if you find the fix
no worries, I will just disable "example" compilation and let it R.I.P.
I managed to figure out the difference. We have BUILD_SHARED_LIBS
flag enabled by default.
You can reproduce it with the following:
cmake -DBUILD_SHARED_LIBS=YES -DLIEF_EXAMPLES=ON -DLIEF_PYTHON_API=OFF CMakeLists.txt
make
The output:
[ 89%] Linking CXX shared library libLIEF.so
[ 89%] Built target LIB_LIEF
[ 90%] Building CXX object examples/cpp/CMakeFiles/dex_reader.dir/dex_reader.cpp.o
[ 90%] Linking CXX executable dex_reader
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: CMakeFiles/dex_reader.dir/dex_reader.cpp.o: in function `main':
dex_reader.cpp:(.text.startup+0x23): undefined reference to `LIEF::Logger::set_level(LIEF::LOGGING_LEVEL)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: dex_reader.cpp:(.text.startup+0xf5): undefined reference to `LIEF::DEX::Parser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: CMakeFiles/dex_reader.dir/dex_reader.cpp.o:(.data.rel.local.DW.ref._ZTIN4LIEF9exceptionE[DW.ref._ZTIN4LIEF9exceptionE]+0x0): undefined reference to `typeinfo for LIEF::exception'
collect2: error: ld returned 1 exit status
make[2]: *** [examples/cpp/CMakeFiles/dex_reader.dir/build.make:96: examples/cpp/dex_reader] Error 1
make[1]: *** [CMakeFiles/Makefile2:365: examples/cpp/CMakeFiles/dex_reader.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
@blshkv It should be ok now: https://github.com/lief-project/LIEF/commit/352fa954a1135544839847fd9079e704b84c63cd
ok, almost there. The last bit:
* QA Notice: Files built without respecting CFLAGS have been detected
* Please include the following list of files in your report:
* /usr/share/LIEF/examples/python/keygen/KeygenMe
* QA Notice: Files built without respecting LDFLAGS have been detected
* Please include the following list of files in your report:
* /usr/share/LIEF/examples/python/keygen/KeygenMe
Would you mind fixing cmake for that file to make sure these flags are passed?
Hi Romain,
I'm trying to compile the latest commit 8d7ec26a93800b0729c2c05be8c55c8318ba3b20 and facing the following issue:
Disclamer: I'm NOT using docker, my environment specs are the following: