Linking error with Poco Net

2019-05-10 19:20发布

问题:

I am stuck trying to get some code to build using the POCO libraries.

I get the following when I try to build

Undefined symbols for architecture x86_64:
  "Poco::Net::SocketAddress::SocketAddress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned short)", referenced from:
      .....
ld: symbol(s) not found for architecture x86_64

Now here is the catch: I am linking with -lPocoFoundation -lPocoNet -lPocoUtil

What am I missing?

(I should say that I am compiling with clang on Mac OS X 10.8.2

回答1:

I have the same problem. I found change xcode build setting is useful. Change C++ Standard Library from libc++(LLVM C++ standard library with C++ 11 support) to libstdc++(GNU C++ standard library). Then it will pass building.



回答2:

I had the same problem and it worked fine for me what Leezi wrote. I'm using version 1.4.6.

The only thing what I had to do more is to compile the Poco library again (because it was compiled for clang with C++11 support):

./configure --config=Darwin64-gcc
make
sudo make install

The other way what you can do is to compile Poco library with C++11 support, but it's a little bit complicated. First I had to modify two source file in Foundation:

Foundation/src/NumberParser.cpp:

127c127
<   return std::sscanf(s.c_str(), "%"I64_FMT"d%c", &value, &temp) == 1;
---
>   return std::sscanf(s.c_str(), "%" I64_FMT "d%c", &value, &temp) == 1;
144c144
<   return std::sscanf(s.c_str(), "%"I64_FMT"u%c", &value, &temp) == 1;
---
>   return std::sscanf(s.c_str(), "%" I64_FMT "u%c", &value, &temp) == 1;
161c161
<   return std::sscanf(s.c_str(), "%"I64_FMT"x%c", &value, &temp) == 1;
---
>   return std::sscanf(s.c_str(), "%" I64_FMT "x%c", &value, &temp) == 1;

Foundation/src/DirectoryWatcher.cpp:

51a52
> #include <unistd.h>

I modified build/config/Darwin-clang file too:

55,56c55,56
< CXXFLAGS        = $(ARCHFLAGS) -Wall -Wno-sign-compare
< LINKFLAGS       = $(ARCHFLAGS)
---
> CXXFLAGS        = $(ARCHFLAGS) -Wall -Wno-sign-compare -std=c++11 -stdlib=libc++
> LINKFLAGS       = $(ARCHFLAGS) -stdlib=libc++
80c80
< SYSLIBS  = -ldl
---
> SYSLIBS  = -ldl -lstdc++

I needed only for static libraries, so I only compiled that:

./configure --static --omit=Data --config=Darwin64-clang --poquito -no-tests -no-samples -no-shared
make clean
make
sudo make install

If you need for samples and tests too, then I think you should make an xcode project and set up it or go deep inside the makefiles... I hope this help...