开发者

symbol lookup error

开发者 https://www.devze.com 2023-04-05 15:19 出处:网络
I am writing a shared library with C++ under Ubuntu. The source code contains two files: ClassA.h and ClassA.cpp. Bellow are parts of the contents:

I am writing a shared library with C++ under Ubuntu. The source code contains two files: ClassA.h and ClassA.cpp. Bellow are parts of the contents:

ClassA.h:

namespace calss_a{
class ClassA{
public:
   ...
   void foo(int nBlockIndex);
   ...
}
}

ClassA.h:

namespace calss_a{
    ...
   void classA::foo(int nBlockIndex){printf("....");}
    ...
}

The compiled .so file from the above source codes is used in test.cpp as follows:

...
class_a::ClassA * ptr = new class_a::ClassA();
...
ptr->foo(0);
...

However, when the executable build from test.cpp runs, there is an error as follows:

symbol lookup error: /home/hzh开发者_开发百科u/test: undefined symbol: _ZN16class_a15ClassA16fooEj

But if I change in ClassA.cpp and ClassA.h the type of foo()'s argument "nBlockIndex" from "int" to "unsigned in", and recompile the .so file, then the problem disappears. In a further experiment, the argument "nBlockIndex"'s type is still defined to be "int", but in test.cpp I call "foo" this way:

ptr->foo(1); //pass 1 instead of 0

then the problem disappear as well.

Can anyone tell me what is going on here?

Thanks.


I am a bit new to this kind of thing myself, but I am also running into a symbol lookup error and so thought I would share what I have found out.

The problem with symbol lookup errors usually is that something is being defined two different ways in two different places. If you do

 nm -u your-executable | grep undefined-symbol

then you will find out where the symbols being used in an object file or executable file are defined

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号