javascript - undefined symbol in node.js C++ addon under Linux, why? - Stack Overflow

I'm a newbie of writing C++ addons in node.js.And this is my module:$ npm install simpleiniIt'

I'm a newbie of writing C++ addons in node.js.

And this is my module:

$ npm install simpleini

It's based on miniini-0.9. And my source is under src/simpleIni. I've tried this module under Windows, OS X, Linux (Debian). It works well under Windows and OS X.

But when I ran in Linux, it appears that:

node: symbol lookup err: .../simpleIni.node: undefined symbol: _ZNK10INISection10ReadStringEPKcRS1_

Why?

I'm a newbie of writing C++ addons in node.js.

And this is my module:

$ npm install simpleini

It's based on miniini-0.9. And my source is under src/simpleIni. I've tried this module under Windows, OS X, Linux (Debian). It works well under Windows and OS X.

But when I ran in Linux, it appears that:

node: symbol lookup err: .../simpleIni.node: undefined symbol: _ZNK10INISection10ReadStringEPKcRS1_

Why?

Share Improve this question edited Jul 28, 2016 at 12:51 signal 4348 silver badges24 bronze badges asked Apr 4, 2014 at 16:35 XadillaXXadillaX 1911 gold badge2 silver badges13 bronze badges 3
  • er... we would need to see a little more of your code than the name or your source file. I'm unsure about how node.js C++ addons are delivered.... but if you have dynamic library (in unix) you can use nm to verify whether the failing symbol is defined or undefined. Does this name INISession10 ReadString rings any bell? something that you've declared and forgotten to define? – jsantander Commented Apr 4, 2014 at 17:01
  • sorry i've not pushed it to github yet. but you can get code through npm install. because it has more than one file. but my source file is just simpleIni – XadillaX Commented Apr 4, 2014 at 17:09
  • Try removing the inline in src/miniini-0.9/miniini/src/inisection.cpp line 125.... – jsantander Commented Apr 4, 2014 at 17:30
Add a ment  | 

1 Answer 1

Reset to default 6

After some searching this is what I've found.

Doing:

$ nm -C build/Release/simpleIni.node  | grep ReadString
                 U INISection::ReadString(char const*, char const*&) const
00000000000032b0 t INISection::ReadString(char const*, char const*&) const [clone .part.11]
0000000000003f80 W INISection::ReadString(std::string const&, std::string&) const
00000000000081a0 T INISection::ReadStrings(char const*, char const**, unsigned int) const
0000000000008f20 T INISection::ReadStrings(std::string const&, std::vector<std::string, std::allocator<std::string> >&) const
000000000000bca0 r INISection::ReadString(char const*, char const*&) const::__PRETTY_FUNCTION__
000000000000b8a0 r INISection::ReadStrings(char const*, char const**, unsigned int) const::__PRETTY_FUNCTION__

So the key is the

                 U INISection::ReadString(char const*, char const*&) const

Which appears as undefined... Although there's another copy of the symbol

00000000000032b0 t INISection::ReadString(char const*, char const*&) const [clone .part.11]

Now we can search for this method in your code:

at src/miniini-0.9/miniini/include/inisection.h

class INISection
{
...
        bool ReadString(const char * const name, const char * & out) const;
}

And in src/miniini-0.9/miniini/src/inisection.cpp

inline bool INISection::ReadString(const char * name, const char * & out) const
{
...
}

Now the key is this inline. According to the C++ FAQ How do you tell the piler to make a member function inline?

The reason you (almost always) put the definition (the {...} part) of an inline function in a header file is to avoid “unresolved external” errors from the linker. That error will occur if you put the inline function’s definition in a .cpp file and if that function is called from some other .cpp file.

removing the inline from the inisection.cpp and rebuilding we can try again the nm

$ nm -C build/Release/simpleIni.node  | grep ReadString
00000000000069a0 T INISection::ReadString(char const*, char const*&) const
0000000000003f70 W INISection::ReadString(std::string const&, std::string&) const
00000000000080e0 T INISection::ReadStrings(char const*, char const**, unsigned int) const
0000000000008d20 T INISection::ReadStrings(std::string const&, std::vector<std::string, std::allocator<std::string> >&) const
000000000000bc20 r INISection::ReadString(char const*, char const*&) const::__PRETTY_FUNCTION__
000000000000b7e0 r INISection::ReadStrings(char const*, char const**, unsigned int) const::__PRETTY_FUNCTION__

This time there are no undefined symbols and the ReadString appears only once.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745343403a4623433.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信