473,396 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 incomprehensible 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 1926
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 incomprehensible 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_map ;

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.comwrote:
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_map;

// fieldmap for OASEquityALloc block
static std::map <string, intoaea_field_map;
....
....
void GTSEqTrdHandler::parse_eqtyBlock (const char* name, string& data)
{
static const char* func = "parse_eqtyBlock:" ;
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@eqzps22d:/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_tree<std::basic_string<char,std::cha r_traits<char>,std::allocator<char>
>,std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,__rwstd::__select1st<std::pai r<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,std::basic_string<char,std::c har_traits<char>,std::allocator<char >,std::less<std::basic_string<char,std::char_trait s<char>,std::allocator<char >,std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int >::iterator __rwstd::__rb_tree<std::basic_string<char,std::cha r_traits<char>,std::allocator<char,std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,__rwstd::__select1st<std::pai r<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,std::basic_string<char,std::c har_traits<char>,std::allocator<char >,std::less<std::basic_string<char,std::char_trait s<char>,std::allocator<char >,std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int >::erase(__rwstd::__rb_tree<std::basic_string<char ,std::char_traits<char>,std::allocator<char,std::p air<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,__rwstd::__select1st<std::pai r<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,std::basic_string<char,std::c har_traits<char>,std::allocator<char >,std::less<std::basic_string<char,std::char_trait s<char>,std::allocator<char >,std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int >::iterator,__rwstd::__rb_tree<std::basic_string<c har,std::char_traits<char>,std::allocator<char,std ::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,__rwstd::__select1st<std::pai r<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,std::basic_string<char,std::c har_traits<char>,std::allocator<char >,std::less<std::basic_string<char,std::char_trait s<char>,std::allocator<char >,std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int >::iterator) ../../install/libencdec.a(GTSSAXHandlers.o)
std::pair<__rwstd::__rb_tree<std::basic_string<cha r,std::char_traits<char>,std::allocator<char>
>,std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,__rwstd::__select1st<std::pai r<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,std::basic_string<char,std::c har_traits<char>,std::allocator<char >,std::less<std::basic_string<char,std::char_trait s<char>,std::allocator<char >,std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int >::iterator,bool>__rwstd::__rb_tree<std::basic_str ing<char,std::char_traits<char>,std::allocator<cha r,std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,__rwstd::__select1st<std::pai r<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,std::basic_string<char,std::c har_traits<char>,std::allocator<char >,std::less<std::basic_string<char,std::char_trait s<char>,std::allocator<char >,std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int >::insert(const std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>&) ../../install/libencdec.a(GTSSAXHandlers.o)
void
__rwstd::__rb_tree<std::basic_string<char,std::cha r_traits<char>,std::allocator<char>
>,std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,__rwstd::__select1st<std::pai r<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int>,std::basic_string<char,std::c har_traits<char>,std::allocator<char >,std::less<std::basic_string<char,std::char_trait s<char>,std::allocator<char >,std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std: :allocator<char,int >::__deallocate_buffers() ../../install/libencdec.a(GTSSAXHandlers.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...@optonline.netwrote:
On Jan 25, 4:21 pm, "Alan Johnson" <a...@yahoo.comwrote:
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,intdeclared 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
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? ...
1
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: --...
1
by: Stefan Slapeta | last post by:
Hi, I've found some strange behaviour with some smart pointers. Consider this little sample: // ********************************************************** struct MyStruct {}; template...
1
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...
2
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...
4
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...
3
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...
1
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,...
1
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.