mailio icon indicating copy to clipboard operation
mailio copied to clipboard

Proper way to compile a project

Open CybersShell opened this issue 3 years ago • 2 comments

Hi,

I am getting errors compiling a sample file, using some of the code in the examples. I am using https://github.com/karastojko/mailio/blob/master/examples/smtps_simple_msg.cpp as a test, using my own mail server.

  • OS: Debian Bullseye
  • Boost version: 1.74 from the Debian repos
  • Compile command: clang++-15 -std=c++17 mail.cpp -o mail
  • also tried with g++

Got this error:

/usr/bin/ld: /tmp/mail-7b0f79.o: in function `main':
mail.cpp:(.text+0xcc): undefined reference to `mailio::message::message()'
/usr/bin/ld: mail.cpp:(.text+0x11a): undefined reference to `mailio::mail_address::mail_address(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: mail.cpp:(.text+0x132): undefined reference to `mailio::message::from(mailio::mail_address const&)'
/usr/bin/ld: mail.cpp:(.text+0x1a4): undefined reference to `mailio::mail_address::mail_address(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: mail.cpp:(.text+0x1bc): undefined reference to `mailio::message::add_recipient(mailio::mail_address const&)'
/usr/bin/ld: mail.cpp:(.text+0x22a): undefined reference to `mailio::message::subject(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: mail.cpp:(.text+0x28c): undefined reference to `mailio::mime::content(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: mail.cpp:(.text+0x2e7): undefined reference to `mailio::smtps::smtps(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, std::chrono::duration<long, std::ratio<1l, 1000l> >)'
/usr/bin/ld: mail.cpp:(.text+0x310): undefined reference to `mailio::smtps::authenticate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mailio::smtps::auth_method_t)'
/usr/bin/ld: mail.cpp:(.text+0x33b): undefined reference to `mailio::smtp::submit[abi:cxx11](mailio::message const&)'
/usr/bin/ld: /tmp/mail-7b0f79.o: in function `mailio::smtps::~smtps()':
mail.cpp:(.text._ZN6mailio5smtpsD2Ev[_ZN6mailio5smtpsD2Ev]+0x11): undefined reference to `mailio::smtp::~smtp()'
/usr/bin/ld: /tmp/mail-7b0f79.o: in function `mailio::message::~message()':
mail.cpp:(.text._ZN6mailio7messageD2Ev[_ZN6mailio7messageD2Ev]+0x17): undefined reference to `vtable for mailio::message'
/usr/bin/ld: /tmp/mail-7b0f79.o: in function `boost::asio::error::detail::ssl_category::message[abi:cxx11](int) const':
mail.cpp:(.text._ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei[_ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei]+0x23): undefined reference to `ERR_reason_error_string'
/usr/bin/ld: /tmp/mail-7b0f79.o: in function `mailio::mime::~mime()':
mail.cpp:(.text._ZN6mailio4mimeD2Ev[_ZN6mailio4mimeD2Ev]+0x17): undefined reference to `vtable for mailio::mime'
/usr/bin/ld: /tmp/mail-7b0f79.o: in function `boost::asio::ssl::detail::openssl_init_base::do_init::~do_init()':
mail.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev]+0x12): undefined reference to `CONF_modules_unload'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

CybersShell avatar Aug 11 '22 21:08 CybersShell

Try something like:

g++ -std=c++17 -I ./include/ -I /opt/boost-1.75.0/include/ -L ./build/ -L /opt/boost-1.75.0/lib/ -L /usr/lib/x86_64-linux-gnu/ test.cpp -o test -lboost_system -lboost_regex -lboost_date_time  -lpthread -lcrypto -lssl -lmailio

Adjust the paths according to your setup.

karastojko avatar Aug 12 '22 11:08 karastojko

After running the above command I get the following error:

/usr/bin/ld: /usr/local/lib/libmailio.a(dialog.cpp.o): undefined reference to symbol 'pthread_condattr_setclock@@GLIBC_2.3.3'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu//libpthread.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

It is weird because I am including the -lpthread link in the g++ command. I have tried solutions mentioned in this thread https://stackoverflow.com/questions/19901934/libpthread-so-0-error-adding-symbols-dso-missing-from-command-line, but no joy so far.

CybersShell avatar Aug 12 '22 17:08 CybersShell

I believe you are mixing the static library libmailio.a together with the shared pthread library. Can you build the shared library version libmailio.so and try again?

karastojko avatar Aug 13 '22 14:08 karastojko

I am closing this issue as I am moving on to Go because I want to create a web mail app.

Also, the README should be updated, specifically this line in the CMAKE section:

Other available options are MAILIO_BUILD_SHARED_LIBRARY (by default is on, if turned off then the static library is built)...

This conflicts with the most recent commit https://github.com/karastojko/mailio/commit/c1d4d2f78bc158045790385471e9ea5fb38fc490.

CybersShell avatar Aug 13 '22 15:08 CybersShell