Discussion:
NEWBIE: Undefined references: How do I find the library that resolves an undefined reference - Expanded with log example and hope for a general solution
(too old to reply)
JENNINGS, LYNN M NH-03 USAF AFMC 517 SMXS/MXDPB
2017-01-25 17:45:49 UTC
Permalink
Thanks Richard and Andy for the timely response! Andy's answers provides the perfect example of my dilemma. When Andy said to check the MSDN documentation for ms742213, I quickly found that I needed the Ws2_32.lib library, which I was able to solve my issue. However, I also have the following:

1. boost::log::add_log_file(...) with a sinks::file::rotation_at_time_point(...)
2. boost::random::random_device range;

I made a guess with the log and added boost_log_setup_mgw48-mt-d-1_61 and boost_log_ mgw48-mt-d-1_61, but these libraries didn't resolve my issue. When I check the boost documentation (I realize that many of the boost additions just require header files, which the examples are careful to specify. I figure this must require a library because I am getting an undefined error.), there were many mentions of a library, but I couldn't find where the name of the library was specified!

So I hope there is a general way to determine the name of the boost library so I do not need to keeping asking about particular undefined errors. In the past, I have been able to google the undefined error and find the library reference, but

Thanks again for all of your help!

-----Original Message-----
That would be the winsock library.
https://msdn.microsoft.com/en-us/library/ms740673.aspx
On 24 January 2017 at 20:33, JENNINGS, LYNN M NH-03 USAF AFMC 517
NEWBIE question: Undefined references: How do I find the library that
resolves an undefined reference. For example, the output for the gcc
C:/boost/boost/asio/detail/impl/winsock_init.ipp:39: Undefined reference
to `WSAStartup_at_8'
I have googled the documentation a number of ways, but I cannot find the
library that will resolve this error. I am sure that this is a common
problem. Please point me to the documentation so I can fix this and the
undefined references.
Thanks!
In the future, you can check Microsoft's documentation [1] for info on
their functions. I searched for "WSAStartup", and found [2]. At the
bottom of that page is a "Requirements" box, which tells you the library
it's in.
Andy
1. http://msdn.microsoft.com
2.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms742213(v=vs.85).aspx
Michael Chisholm
2017-01-26 02:32:39 UTC
Permalink
On 1/25/2017 12:45 PM, JENNINGS, LYNN M NH-03 USAF AFMC 517 SMXS/MXDPB
Post by JENNINGS, LYNN M NH-03 USAF AFMC 517 SMXS/MXDPB
1. boost::log::add_log_file(...) with a sinks::file::rotation_at_time_point(...)
2. boost::random::random_device range;
I made a guess with the log and added boost_log_setup_mgw48-mt-d-1_61 and boost_log_ mgw48-mt-d-1_61, but these libraries didn't resolve my issue. When I check the boost documentation (I realize that many of the boost additions just require header files, which the examples are careful to specify. I figure this must require a library because I am getting an undefined error.), there were many mentions of a library, but I couldn't find where the name of the library was specified!
So I hope there is a general way to determine the name of the boost library so I do not need to keeping asking about particular undefined errors. In the past, I have been able to google the undefined error and find the library reference, but
Thanks again for all of your help!
I see you're using MinGW-built libraries. MinGW comes with some tools
that might help you. So this isn't boost-specific advice, but more general.

Have you tried some of the relevant MinGW tools? I found some old
MinGW-built boost libs lying around, and the following worked to show me
exports. From a MinGW shell:

$ nm -Cg ./libboost_log-mgw48-mt-1_54.dll

that dumped a ton of info to the console. You can filter using 'grep'
to search for things:

$ nm -Cg ./libboost_log-mgw48-mt-1_54.dll | grep rotation_at_time_point

One of the entries I got was:

00000000653d4f00 T
boost::log::v2_mt_nt5::sinks::file::rotation_at_time_point::rotation_at_time_point(unsigned
char, unsigned char, unsigned char)

(it's one of several overloads.) If someone suggests an easier way of
matching up boost symbols to DLLs, great, but if you have nothing else,
this can help. (There some other similar tools too, but hopefully 'nm'
will work.)

Additionally, with gcc, order of libraries given on the commandline
matters. If you get it wrong, then even if the symbol you need is in
the DLL, and the DLL is on your commandline, you'll get the linker
error. Dependent libraries should always come before their dependencies.

Hope this helps,
Andy
JENNINGS, LYNN M NH-03 USAF AFMC 517 SMXS/MXDPB
2017-01-26 18:47:41 UTC
Permalink
Thanks again Andy!

I am sending this note to thank Andy for his gracious help and to document the resolution for future newbies.

Andy's suggestion to "nm -Cg" the boost.log directories was just what I needed! (Sorry, I should have remembered the -C option when I got nothing but garbage.)

What I found was that the header files I use, generate a reference to ...::v2s_mt_nt5::..., while the libraries only define the namespace with ...::v2_mt_nt5::...

For example, my code has the following:

#include <boost\log\core.hpp>
#include <boost\log\trivial.hpp>
#include <boost\log\expressions.hpp>
#include <boost\log\utility\setup\file.hpp>
#include <boost\log\utility\setup\common_attributes.hpp>
namespace logging = boost::log ;
namespace src = boost::log::sources ;
namespace keywords= logging::keywords ;
namespace sinks = boost::log::sinks ;

void init_logger() {
logging::add_file_log(
"sample.log",
keywords::rotation_size = 10 * 1024 * 1024,
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0,0,0),
keywords::format = "[%TimeStamp%]: %Message%",
keywords::auto_flush=true
) ;
logging::core::get()->set_filter (logging::trivial::severity >= logging::trivial::info ) ;
logging::core::get()->add_global_attribute("TimeStamp", boost::log::attributes::local_clock());
}
...

I compiled with the following command from my makefile:

cc -g -DCPU=PENTIUM -DMC68000 -DDoing2VxWorks -IC:\boost -I../source -I../include -MMD -MP -c -o obj\logLib.o logLib.cpp

Which I built with the following command from my makefile:

cc -g -DCPU=PENTIUM -DMC68000 -DDoing2VxWorks -IC:\boost -I../source -I../include -MMD -MP -c -o obj\logLib.o logLib.cpp
gfortran -o unit01test.exe obj\unit01test.o ..\mcpmain\obj\rtinit.o ..\mcpmain\obj\bite2.o ..\mcpmain\obj\bmain.o ..\mcpmain\obj\keypm2.o ..\mcpmain\obj\ksvc.o ..\mcpmain\obj\scen1.o ..\mcpmain\obj\disup.o ..\mcpmain\obj\idisup.o ..\mcpmain\obj\keyin.o ..\mcpmain\obj\disdr.o ..\mcpmain\obj\led_task.o ..\mcpmain\obj\spip_task.o ..\mcpmain\obj\iff_task.o ..\mcpmain\obj\inmsgmgr.o ..\mcpmain\obj\cppmainUnit01Test.o ..\runhistory\obj\rhlog_api.o ..\utilities\obj\main2aux.o ../../vxWorksLib/vxWorksLib/vxWorks/source/obj\logLib.o ../../vxWorksLib/vxWorksLib/vxWorks/source/obj\msgQlib.o ../../vxWorksLib/vxWorksLib/vxWorks/source/obj\pciConfigLib.o ../../vxWorksLib/vxWorksLib/vxWorks/source/obj\semLib.o ../../vxWorksLib/vxWorksLib/vxWorks/source/obj\sharedMemLib.o ../../vxWorksLib/vxWorksLib/vxWorks/source/obj\sockLib.o ../../vxWorksLib/vxWorksLib/vxWorks/source/obj\sysLib.o ../../vxWorksLib/vxWorksLib/vxWorks/source/obj\taskLib.o ../../vxWorksLib/vxWorksLib/vxWorks/source/obj\wdLib.
o -LC:\boost\stage\lib -lboost_log_setup-mgw48-mt-d-1_61 -lboost_log-mgw48-mt-d-1_61 -lboost_thread-mgw48-mt-d-1_61 -lboost_system-mgw48-mt-d-1_61 -LC:\Windows\SysWOW\en-US -lws2_32 -lstdc++ -lboost_log_setup-mgw48-mt-d-1_61 -lboost_log-mgw48-mt-d-1_61

which gives me the error:

../../vxWorksLib/vxWorksLib/vxWorks/source/obj\logLib.o: In function `Z11init_loggerv':
c:\1PortMUTES2MinGW\ProjectRepository-Build\vxWorksLib\vxWorksLib\vxWorks\source/logLib.cpp:16: undefined reference to `boost::log::v2s_mt_nt5::sinks::file::rotation_at_time_point::rotation_at_time_point(unsigned char, unsigned char, unsigned char)'

But when I check the nm output, I find the following ::v2_mt_nt5:: namespace defined in all of the various forms of the Boost log libraries:

d000608.o:
U _head_libboost_log_mgw48_mt_d_1_61_dll
00000000 I _imp___ZNK5boost3log9v2_mt_nt55sinks4file25rotation_at_time_intervalclEv
00000000 T boost::log::v2_mt_nt5::sinks::file::rotation_at_time_interval::operator()() const

I built my boost libraries using the directions for a MinGW build. I built my code using the same MinGW framework.

However, I found the reason for the two conflicting name spaces, v2_mt_nt5 and v2s_mt_nt5 at:

http://www.boost.org/doc/libs/1_56_0/libs/log/doc/html/log/rationale/namespace_mangling.html

The magic key is to recognize the <linkage> name space. I resolved most of my Boost log problem by adding -DBOOST_ALL_DYN_LINK to the compile operation. The correct compile command is:

cc -g -DCPU=PENTIUM -DMC68000 -DDoing2VxWorks - DBOOST_ALL_DYN_LINK -IC:\boost -I../source -I../include -MMD -MP -c -o obj\logLib.o logLib.cpp

Note that I was able to resolve my remaining errors where gcc just listed the mangled symbol by grep'ing the library file.
Loading...