How to fix C++ static linking problems?
March 26, 2009 6:33 AM Subscribe
I need some help diagnosing a problem static linking a C++ program using g++. It compiles and runs just fine without "-static", but I get all sorts of "undefined references" errors when I use "-static". I'm a C++ novice and am at a loss. Can anyone throw me a bone?
I'm using g++ v4.32 running on Debian Lenny.
As I said, it compiles, links, and runs with no problem using dynamic linking. It just breaks with "-static". This is also why I didn't post the source code, though I can if it would be helpful.
Aside from the standard C++ stuff (iostream, ifstream), I'm only using the vmime library and two libraries that it requires (gsasl and gnutls). I installed gsasl and gnutls using apt-get, but I built libvmime from source with no errors. Libvmime's ./configure defaults to building both static and dynamic versions of the library, and I've confirmed that both libvmime.a and libvmime.o exist. I also confirmed that .a files exist for both gsasl and gnutls.
Here's my compile command line:
g++ `pkg-config --cflags --libs vmime` -static -o mimetest mimetest.cpp
The pkg-config bit expands to:
-I/usr/local/include/ -L/usr/local/lib -lvmime -lgnutls -lgsasl
I've confirmed that libvmime exists under /usr/local/lib, and gnutls and gsasl exist under /usr/lib.
I've posted the errors below. Any suggestions?
Thanks,
M
------------------------------------------------------------------------------
/tmp/ccioHkjN.o: In function `loadX509CertificateFromFile(std::basic_string, std::allocator > const&)':
mimetest.cpp:(.text+0x140): undefined reference to `vmime::utility::inputStreamAdapter::inputStreamAdapter(std::basic_istream >&
)'
mimetest.cpp:(.text+0x15d): undefined reference to `vmime::security::cert::X509Certificate::import(vmime::utility::inputStream&)'
/tmp/ccioHkjN.o: In function `main':
mimetest.cpp:(.text+0x2681): undefined reference to `vmime::security::cert::defaultCertificateVerifier::setX509RootCAs(std::vector, std::allocator > > const&)'
mimetest.cpp:(.text+0x2703): undefined reference to `vmime::net::session::getProperties()'
mimetest.cpp:(.text+0x27f5): undefined reference to `vmime::net::session::getProperties()'
mimetest.cpp:(.text+0x28dd): undefined reference to `vmime::net::session::getProperties()'
mimetest.cpp:(.text+0x29c8): undefined reference to `vmime::net::session::getProperties()'
mimetest.cpp:(.text+0x2ab2): undefined reference to `vmime::utility::url::url(std::basic_string, std::allocator > const&)'
mimetest.cpp:(.text+0x2b5c): undefined reference to `vmime::net::session::getStore(vmime::utility::url const&, vmime::utility::ref)'
mimetest.cpp:(.text+0x2c0b): undefined reference to `vmime::net::service::setCertificateVerifier(vmime::utility::ref)'
mimetest.cpp:(.text+0x2d60): undefined reference to `vmime::charsets::UTF_8'
mimetest.cpp:(.text+0x2d72): undefined reference to `vmime::charset::charset(char const*)'
----------------------------------------------------------------
Cut out some...
----------------------------------------------------------------
/tmp/ccioHkjN.o: In function `vmime::header::Date() const':
mimetest.cpp:(.text._ZNK5vmime6header4DateEv[vmime::header::Date() const]+0x1b): undefined reference to `vmime::fields::DATE'
mimetest.cpp:(.text._ZNK5vmime6header4DateEv[vmime::header::Date() const]+0x4a): undefined reference to `vmime::header::findField(std::basic_string, std::allocator > const&) const'
/tmp/ccioHkjN.o: In function `vmime::header::From() const':
mimetest.cpp:(.text._ZNK5vmime6header4FromEv[vmime::header::From() const]+0x1b): undefined reference to `vmime::fields::FROM'
mimetest.cpp:(.text._ZNK5vmime6header4FromEv[vmime::header::From() const]+0x4a): undefined reference to `vmime::header::findField(std::basic_string, std::allocator > const&) const'
/tmp/ccioHkjN.o: In function `vmime::header::Subject() const':
mimetest.cpp:(.text._ZNK5vmime6header7SubjectEv[vmime::header::Subject() const]+0x1b): undefined reference to `vmime::fields::SUBJECT'
mimetest.cpp:(.text._ZNK5vmime6header7SubjectEv[vmime::header::Subject() const]+0x4a): undefined reference to `vmime::header::findField(std::basic_string, std::allocator > const&) const'
/tmp/ccioHkjN.o: In function `vmime::charset::~charset()':
mimetest.cpp:(.text._ZN5vmime7charsetD1Ev[vmime::charset::~charset()]+0xd): undefined reference to `vtable for vmime::charset'
mimetest.cpp:(.text._ZN5vmime7charsetD1Ev[vmime::charset::~charset()]+0x2c): undefined reference to `vmime::component::~component()'
mimetest.cpp:(.text._ZN5vmime7charsetD1Ev[vmime::charset::~charset()]+0x50): undefined reference to `vmime::component::~component()'
/tmp/ccioHkjN.o: In function `vmime::utility::url::~url()':
mimetest.cpp:(.text._ZN5vmime7utility3urlD1Ev[vmime::utility::url::~url()]+0x12): undefined reference to `vmime::propertySet::~propertySet()'
/tmp/ccioHkjN.o:(.rodata._ZTVN5vmime7utility11inputStreamE[vtable for vmime::utility::inputStream]+0x10): undefined reference to `vmime::utility::stream::get
BlockSize() const'
/tmp/ccioHkjN.o:(.rodata._ZTIN5vmime7utility11inputStreamE[typeinfo for vmime::utility::inputStream]+0x8): undefined reference to `typeinfo for vmime::utilit
y::stream'
collect2: ld returned 1 exit status
posted by duoshao to computers & internet (9 answers total) 3 users marked this as a favorite
posted by mkb at 6:58 AM on March 26, 2009