Unable to associate the application with dirt

My application uses my shared library. The application and library should be mudflapped to check the read and write boundaries both on the stack and on the heap. The shared library was successfully created, but I had a lot of errors when linking the application.

I made a simple example that reproduces this problem. Here are the steps to play:

  • create a C ++ dynamic shared library project with two files: h and cpp files with some class, and in the h or cpp file use #include <iostream>
  • create a C ++ application that uses this library (uses a class from a shared library)
  • build a library
  • build an application (here you will catch a communication error)

Here are my files:

SharedLibTest.h

 #ifndef SHAREDLIBTEST_H_ #define SHAREDLIBTEST_H_ #include <iostream> class SharedLibTest { public: void func(); }; #endif /* SHAREDLIBTEST_H_ */ 

SharedLibTest.cpp

 #include "SharedLibTest.h" void SharedLibTest::func() {} 

main.cpp

 #include <SharedLibTest.h> int main(int argc, char *argv[]) { SharedLibTest obj; obj.func(); return 0; } 

Building a library:

 g++ -O0 -g3 -Wall -c -fmessage-length=0 -fmudflap -funwind-tables -fPIC -MMD -MP -MF"SharedLibTest.d" -MT"SharedLibTest.d" -o "SharedLibTest.o" "../SharedLibTest.cpp" g++ -rdynamic -shared -o "libshared_lib.so" ./SharedLibTest.o -lmudflap 

Application Building:

 g++ -I"/home/msviridov/work/prj/workspace/shared_lib" -O0 -g3 -Wall -c -fmessage-length=0 -fmudflap -funwind-tables -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp" g++ -L"/home/msviridov/work/prj/workspace/shared_lib/Debug" -rdynamic -v -o "executable" ./main.o -lshared_lib -lmudflap 

Linker Error Output:

 /home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<unsigned long>::__digits' /home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<long>::__min' /home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<short>::__min' /home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<char>::__max' /home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<short>::__max' /home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<long>::__max' /home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<int>::__max' /home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<int>::__min' collect2: ld returned 1 exit status make: *** [executable] Error 1 

Although, if I remove the mudflap compiler and linker flags for the library, building the application will succeed. But this is not the case for the opposite.

I do not understand what leads to this result. My platform is Linux Mint 13 Maya 64 bit. I would appreciate any help. Thanks.

+4
source share
2 answers

Remove #include <iostream> from your header file. If you want to include iostream do this in the source file (SharedLibTest.cpp).

Inclusion in the header file also includes a lot of garbage for you, and may also cause some reference errors like this. Create SharedLibTest.o without it, enable and compare the sizes of the object files.

+2
source

You will probably click error 53359 , but you will need the latest 4.8 code to verify. Also, keep in mind that mudflap is for C and very simple C ++ programs so that you can find false possibilities (ala bug 19319 ) and does not work with DSO yet .

0
source

Source: https://habr.com/ru/post/1436780/


All Articles