我的应用程序使用我的共享库。应用程序和库必须mudflapped
来检查超出堆栈和堆的读写区域。共享库已成功构建,但在链接应用程序时,我遇到了很多错误。
我做了一个简单的例子来重现这个问题。以下是重现的步骤:
#include <iostream>
以下是我的文件:
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;
}
构建库:
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
构建应用程序:
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
链接器错误输出为:
/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
但是,如果我删除了库的mudflap编译器和链接器标志,应用程序的构建将成功完成。 但事实并非如此,反之亦然。
我不明白导致这种结果的原因是什么。 我的平台是Linux Mint 13 Maya 64位。我会感激任何帮助。感谢。
答案 0 :(得分:2)
从头文件中删除#include <iostream>
。如果要在源(SharedLibTest.cpp)文件中包含iostream
,请执行此操作。
将它包含在头文件中还会包含大量垃圾,也可能会导致一些像这样的引用错误。创建没有包含的SharedLibTest.o并比较目标文件的大小。
答案 1 :(得分:0)
你可能正在点击bug 53359,但你需要最近的4.8代码来检查。此外,请注意,mudflap适用于C and very simple C++ programs,因此您可能会发现错误的可能性(ala bug 19319)和doesn't work with DSOs yet。