473,698 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linker complains about unresolved symbol in STL mapp class

I declared a static std::map<string , intin one.cpp at the module
level. This is only used inside the file and I did it to avoid global
namespace pollution

The file one.o goes into the library archive mylib.a

Then when I try to compile file two.cpp, which links to mylib.a, the
linker spits out incomprehensibl e messages about undefined symbols. I
understood them enough to know that it's complaining about methods of
the map class being undefined.

Any relief here? I saw some esoteric discussions on C++ FAQ Lite, but
missed the point.

Thanks a lot for your kind responses!
Vijay

Jan 25 '07 #1
3 1942
Vijay Bajwa wrote:
I declared a static std::map<string , intin one.cpp at the module
level. This is only used inside the file and I did it to avoid global
namespace pollution

The file one.o goes into the library archive mylib.a

Then when I try to compile file two.cpp, which links to mylib.a, the
linker spits out incomprehensibl e messages about undefined symbols. I
understood them enough to know that it's complaining about methods of
the map class being undefined.

Any relief here? I saw some esoteric discussions on C++ FAQ Lite, but
missed the point.

Thanks a lot for your kind responses!
Vijay
Not enough information. Show some code that demonstrates the problem
you are having. Show us the error message you are getting. I just
tried to reproduce your problem and got no errors. Here was my test
setup.

one.cpp:
#include <map>
#include <string>

static std::map<int, std::stringmy_m ap ;

void init()
{
my_map[1] = "Hello" ;
my_map[2] = " world" ;
}

std::string f(unsigned i)
{
return my_map[i] ;
}

two.cpp:
#include <iostream>
#include <string>

void init() ;
std::string f(unsigned i) ;

int main()
{
init() ;
std::cout << f(1) << f(2) << std::endl ;
}

Build with:
$ g++ -W -Wall -ansi -pedantic -c one.cpp two.cpp
$ ar sr libone.a one.o
ar: creating libone.a
$ g++ -otest two.o -L. -lone
$ ./test
Hello world

--
Alan Johnson

Jan 26 '07 #2


On Jan 25, 4:21 pm, "Alan Johnson" <a...@yahoo.com wrote:
Vijay Bajwa wrote:
I declared a static std::map<string , intin one.cpp at the module
VijayNot enough information. Show some code that demonstrates the problem
you are having. Show us the error message you are getting. I just
tried to reproduce your problem and got no errors. Here was my test
setup.
.... snip...

-------------------------------- GTSSAXHandlers. cpp
-----------------------------
// string has a default compare functor <lessdefined to order strings
static std::map <string, intoaeb_field_m ap;

// fieldmap for OASEquityALloc block
static std::map <string, intoaea_field_m ap;
....
....
void GTSEqTrdHandler ::parse_eqtyBlo ck (const char* name, string& data)
{
static const char* func = "parse_eqtyBloc k:" ;
static char* errMsg ;
const char* chdata = data.c_str();

if (!chdata) {
ERROUT << func << "no data for tag: " << name << ENDL
return ;
}

VDBGOUT << func << "tag=" << name << ", data=" << data << ENDL
.....
----------------------------- end GTSSAXhandlers. cpp
-------------------------------------

compile and add to library archive:
sun4-cross[GTS-Oasys]: make install
/xenv/Forte/sun4/7.0/5.8p4/prod/bin/CC -D_REENTRANT -g -Dsvr4 -DSVR4
-DSUN -DCPLUSREL=7.0 -DOSREV=5.8p4 -DY2K -DCOMPILE_STYLE= CPP_COMPILE
-DTYPE_TOKEN_1=\ "C\" -I../include -I/home/vb11258/OAD5.0/src/include
-I/xenv/OasysDirect/sun4/5.8p4/3.0/src/include
-I/xenv/xerces-c++/sun4/5.8p4/2.2.0/include -c GTSSAXHandlers. cpp
/xenv/OS/sun4/5.8p4/sun4u/ccs/bin/ar rv libencdec.a GTSSAXHandlers. o
r - GTSSAXHandlers. o
ar: writing libencdec.a
/xenv/OS/sun4/5.8p4/sun4u/ccs/bin/ranlib libencdec.a
/usr/ucb/install libencdec.a ../../install
Then go to the directory that has a program that links to this archive.
Note that the program does not even call call the above piece of code
that has the std::map. So here goes:
vb11258@eqzps22 d:/home/vb11258/work/GTS-Oasys/src/driver
sun4-cross[GTS-Oasys]: make
/xenv/Forte/sun4/7.0/5.8p4/prod/bin/CC -D_REENTRANT -g -Dsvr4 -DSVR4
-DSUN -DCPLUSREL=7.0 -DOSREV=5.8p4 -DY2K -DCOMPILE_STYLE= CPP_COMPILE
-DTYPE_TOKEN_1=\ "C\" -I../include -I/home/vb11258/OAD5.0/src/include
-I/xenv/OasysDirect/sun4/5.8p4/3.0/src/include
-I/xenv/xerces-c++/sun4/5.8p4/2.2.0/include -c DecoderMain.cpp
/xenv/Forte/sun4/7.0/5.8p4/prod/bin/CC -D_REENTRANT -g -Dsvr4 -DSVR4
-DSUN -DCPLUSREL=7.0 -DOSREV=5.8p4 -DY2K -DCOMPILE_STYLE= CPP_COMPILE
-DTYPE_TOKEN_1=\ "C\" -I../include -I/home/vb11258/OAD5.0/src/include
-I/xenv/OasysDirect/sun4/5.8p4/3.0/src/include
-I/xenv/xerces-c++/sun4/5.8p4/2.2.0/include -g -Bdynamic -zignore
-Qoption ld -t -mt -Bdynamic -lposix4 -o DecoderMain DecoderMain.o
.../../install/liboaphapp.a ../../install/libencdec.a
.../../install/libOAPHUtils.a -Bdynamic -L
/xenv/xerces-c++/sun4/5.8p4/2.2.0/lib -lxerces-c
-L/xenv/OasysDirect/sun4/5.8p4/3.0/lib -loasdirect -L
/xenv/mqi/sun4/5.x/5.3.0.5/lib -Bdynamic -lmqic -lmqmcs -lmqmzse
-limqb23as -limqc23as -lpthread
Undefined first referenced
symbol in file
__rwstd::__rb_t ree<std::basic_ string<char,std ::char_traits<c har>,std::alloc ator<char>
>,std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,__rw std::__select1s t<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,std: :basic_string<c har,std::char_t raits<char>,std ::allocator<cha r >,std::less<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar >,std::allocato r<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int >::iterator __rwstd::__rb_t ree<std::basic_ string<char,std ::char_traits<c har>,std::alloc ator<char,std:: pair<const std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,__rw std::__select1s t<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,std: :basic_string<c har,std::char_t raits<char>,std ::allocator<cha r >,std::less<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar >,std::allocato r<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int >::erase(__rwst d::__rb_tree<st d::basic_string <char,std::char _traits<char>,s td::allocator<c har,std::pair<c onst std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,__rw std::__select1s t<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,std: :basic_string<c har,std::char_t raits<char>,std ::allocator<cha r >,std::less<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar >,std::allocato r<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int >::iterator,__r wstd::__rb_tree <std::basic_str ing<char,std::c har_traits<char >,std::allocato r<char,std::pai r<const std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,__rw std::__select1s t<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,std: :basic_string<c har,std::char_t raits<char>,std ::allocator<cha r >,std::less<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar >,std::allocato r<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int >::iterator) ../../install/libencdec.a(GTS SAXHandlers.o)
std::pair<__rws td::__rb_tree<s td::basic_strin g<char,std::cha r_traits<char>, std::allocator< char>
>,std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,__rw std::__select1s t<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,std: :basic_string<c har,std::char_t raits<char>,std ::allocator<cha r >,std::less<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar >,std::allocato r<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int >::iterator,boo l>__rwstd::__rb _tree<std::basi c_string<char,s td::char_traits <char>,std::all ocator<char,std ::pair<const std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,__rw std::__select1s t<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,std: :basic_string<c har,std::char_t raits<char>,std ::allocator<cha r >,std::less<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar >,std::allocato r<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int >::insert(con st std::pair<const std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>&) ../../install/libencdec.a(GTS SAXHandlers.o)
void
__rwstd::__rb_t ree<std::basic_ string<char,std ::char_traits<c har>,std::alloc ator<char>
>,std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,__rw std::__select1s t<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int>,std: :basic_string<c har,std::char_t raits<char>,std ::allocator<cha r >,std::less<std ::basic_string< char,std::char_ traits<char>,st d::allocator<ch ar >,std::allocato r<std::pair<con st std::basic_stri ng<char,std::ch ar_traits<char> ,std::allocator <char,int >::__deallocate _buffers() ../../install/libencdec.a(GTS SAXHandlers.o)
ld: fatal: Symbol referencing errors. No output written to DecoderMain
*** Error code 1
make: Fatal error: Command failed for target `DecoderMain'

Funny thing is, when DecoderMain was in the directory containing the
std::map code, and I was directly linking DecoderMain.o to
GTSSAXhandlers. o all was well. Go figure!

Alan, thanks for taking the time to try this out!

Regards,
Vijay

Jan 26 '07 #3


On Jan 25, 9:26 pm, "Vijay Bajwa" <vba...@optonli ne.netwrote:
On Jan 25, 4:21 pm, "Alan Johnson" <a...@yahoo.com wrote:
Vijay Bajwa wrote:
I declared a static std::map<string , intin one.cpp at the module
VijayNot enough information. Show some code that demonstrates the problem
you are having. Show us the error message you are getting. I just
tried to reproduce your problem and got no errors. Here was my test
setup.... snip...
By putting the following 2 lines in two.cpp main() the problem was
resolved:
std::map<string , intmymap;
mymap["one"] = 1;

The following line in two.cpp main also resolved the problem:

XMLDecoder myDecoder;

The XMLDecoder builds the static map<string,intd eclared in one.cpp,
ie calls the insertion method. I guess declaring a static object at
file scope (thus causing constructors to run before main) wasn't enough
for the compiler to generate code for the class?

Also, what is mystifying is that XMLDecoder objet is instantiated in
one of the thread functions, just not in main. I'm chalking it upto the
Forte compiler and/or Rougue Wave STL libraries that compiler uses (I
think. I see a lpt of rw stuff in all the C++ header files).

Regards,
Vijay

Jan 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1450
by: KS | last post by:
I am getting linker error for a code that was tested and running. I opened the project in VS.NET 2003 and now i get these errors - I am sure it is some options issue. Can anyone please help? Linking... atls.lib(atlbase.obj) : error LNK2001: unresolved external symbol ___security_cookie PenPacketInfoDlg.obj : error LNK2019: unresolved external
1
2077
by: Rebecca Hoffmann | last post by:
Hi, I have a serious problem while compiling a small project (a part of the Modular Flow Scheduling Middleware: ex1): There are 3 linker errors, all from symbols that point to templates: -- verbose build output -------------------------------------------- ex1.obj : error LNK2001: unresolved external symbol "public: virtual
1
1326
by: Stefan Slapeta | last post by:
Hi, I've found some strange behaviour with some smart pointers. Consider this little sample: // ********************************************************** struct MyStruct {}; template <typename T> struct Wrapper
1
1923
by: endo55 | last post by:
Hi I've got the following errors when trying to compile a program cvision error LNK2001: unresolved external symbol _IID_IGraphBuilde cvision error LNK2001: unresolved external symbo _IID_IFileSinkFilter cvision error LNK2001: unresolved external symbol _IID_ICreateDevEnu cvision error LNK2001: unresolved external symbol _IID_IBaseFilte cvision error LNK2001: unresolved external symbol _IID_IAMVideoProcAm
2
3385
by: Senapathy | last post by:
VC++ .NET 2003 Standard Edition Win XP, SP2 Hi, I have a code that builds under VC6.0, but fails to link in VC7.1. The offending code is as follows: _AFX_RICHEDIT_STATE* const pEditState = _afxRichEditState;
4
1826
by: Joel Whitehouse | last post by:
Hello All, I have a Visual C++ 2003 dll solution in a directory called "Antenna Test Range Control", and when I comile it, I get the error LNK1104: cannot open file "antenna.obj". When I remove teh spaces in my solution directory, I get the following errors: MastController.exp : error LNK2001: unresolved external symbol _Calibrate@8 MastController.exp : error LNK2001: unresolved external symbol _Initialize@8 MastController.exp :...
3
8066
by: Chucker | last post by:
Hi Folks, I got a Wrapper Dll around a native C++ static library. In .NET 1.1 this worked fine. When moving to .NET 2.0 I get a couple of unresolved externals / linker errors: Error 16 error LNK2028: unresolved token (0A000007) "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)" (?___CxxCallUnwindDtor@@$$J0YMXP6MXPAX@Z0@Z) referenced in function "public: virtual __thiscall...
1
3290
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly, but throws a load of linker errors
1
10355
by: iiitsunny | last post by:
i have ported one project which was working in VC6 to VC7. Now the project is working fine in VC7 also. I have made some additions in VC7 environment only. But the problem is that the project is not working in the release mode. I mean it is shooting off linking errors. I am required to generate an exe file and am looking for some suggestions!!! thank you all Linker Errors are something like this... error LNK2001: unresolved external...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.