Solved

Linker Error - undefined reference to std::wcout

Posted on 2008-06-18
15
1,576 Views
Last Modified: 2012-06-21
I am using g++ and mingw library to compile and link my code. It is compiling fine but when I tried to link the code it is giving me n number of linking error....  most of the linking error is due to wchar_t.... i.e. widechar related...

I have linked my program with -lstdc++. Do I need to include some other library for linking?

some errors...
undefined reference to `std::basic_string<wchar_t, .....
undefined reference to `std::wcout`
undefined reference to `std::basic_ostream<wchar_t, .....
0
Comment
Question by:dennis_george
  • 6
  • 3
  • 3
  • +3
15 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 50 total points
ID: 21818841
Are you using

#define UNICODE

at the top of your 'includes'?
0
 
LVL 5

Author Comment

by:dennis_george
ID: 21818861
Yes UNICODE is given as the compiler option
0
 
LVL 5

Author Comment

by:dennis_george
ID: 21818876
Earlier it was giving my compilation error.... because in the header file wchar_t was defined under _GLIBCXX_USE_WCHAR_T.... When I gave this also as commandline option then the compile time error went but I got those linker errors.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 13

Assisted Solution

by:compfixer101
compfixer101 earned 25 total points
ID: 21819552
could you give us the code for it, all of it that is, so we can see what it is all doing..
I use MS visio studio myself...
0
 
LVL 5

Author Comment

by:dennis_george
ID: 21819628
Code is as calling wcout.

Following is my compiler option
g++ -D_UNICODE -D_GLIBCXX_USE_WCHAR_T -O0 -g3 -Wall -c -fmessage-length=0 -omain.o ..\main.cpp

This gave no error or warning creating main.o object file.

During linking... i.e.
g++ -oTest.exe main.o -lstdc++

I am getting following error....
 undefined reference to `std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::basic_string(wchar_t const*, std::allocator<wchar_t> const&)'
H:/common/generic/security/swi/sistools/source/TestE/Debug/../main.cpp:10: undefined reference to `std::wcout'

gcc version used
gcc version 3.4.5 (mingw-vista special r3)

int main()
	{
	wstring str(L"hello");
	wcout << str << endl;
	wcout << L"Hello World :: " << endl;
	return 0;
	}

Open in new window

0
 
LVL 13

Expert Comment

by:compfixer101
ID: 21819648
yeah, i never used that program, and i always just used cout not wcout
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21820251
Re your example http:#21819628 You need to include the headers <iostream> and <string> and ensure you either prefix a std:: or have a using namespace std;
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
	wstring str(L"hello");
	wcout << str << endl;
	wcout << L"Hello World :: " << endl;
	return 0;
}

Open in new window

0
 
LVL 5

Author Comment

by:dennis_george
ID: 21820376
The includes are proper and I am have the namespace statement in my code... That is just a portion of my code which gives error..

And if those things were missing I won't get linker error but compile time error.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21820400
>> And if those things were missing I won't get linker error but compile time error
Just making sure we are all playing on the same field :)

Have you tried not explicitly providing a C++ runtime to link against...

g++ -o Test.exe main.o

Also have you tried skipping the object stage and compiling/linking in one go?

g++ main.cpp -o Test.exe

I presume it works fine if you use narrow streams/strings?
0
 
LVL 5

Author Comment

by:dennis_george
ID: 21820756
>Have you tried not explicitly providing a C++ runtime to link against...
yes I tried that also.....

More Info:
I am working on Mingw(5.1.4) library. And narrow streams and strings are working fine.... I also need to provide _UNICODE and _GLIBCXX_USE_WCHAR_T to get it compiled.
I think the mingw 5.1.4 does not have wide char support.. That may be the reason that it is missing frm the C++ runtime.
Now trying stlport to fix the issue... But it has its own set of problems :(

0
 
LVL 40

Accepted Solution

by:
evilrix earned 200 total points
ID: 21820805
>> I think the mingw 5.1.4 does not have wide char support.. That may be the reason that it is missing frm the C++ runtime.

I've not used it but during my involvement in another Q another expert confirmed that wide stream support is limited.

{http:Q_23487899.html#21794270}
0
 
LVL 1

Assisted Solution

by:sleep_pilot
sleep_pilot earned 25 total points
ID: 21822944
Why don't you use the native C++RT provided with g++?
0
 
LVL 13

Expert Comment

by:compfixer101
ID: 21824308
if possible try another compiler program.
to rule out the support issue of the widechar support
0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 200 total points
ID: 21829786
According to http://www.mingw.org/MinGWiki/index.php/wide%20characters you need to use STLPort instead of libstdc++. Looks like hard work to me. Do you really need wide characters and really need mingw?
0
 
LVL 5

Author Comment

by:dennis_george
ID: 21830018
Yes I want wide char support and on mingw.... Afer some efforts with STLPort the errors are gone.... Now its working fine.....  

Thanks everybody....
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MSVCR80.dll crash 2 140
multi threaded debug dll option in visual studio 2 109
Grammars for C C++ and java 1 122
Arduino EDI - Programming language 3 95
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question