We help IT Professionals succeed at work.

Unresolved external symbol with STLPORT

1,066 Views
Last Modified: 2013-12-14
Hi expert,

I am not sure why I recieved the following external unresolved symbol after I include the stlport library.

mytest.lib(test.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class _STL::basic_ostream<char,struct _STL::char_traits<char> > & __thiscall _STL::basic_ostream<char,struct _STL::char_traits<char> >::operator<<(class _STL::basic_ostream<char,struct _STL::char_traits<char> > & (__cdecl*)(class _STL::basic_ostream<char,struct _STL::char_traits<char> > &))" (__imp_??6?$basic_ostream@DU?$char_traits@D@_STL@@@_STL@@QAEAAV01@P6AAAV01@AAV01@@Z@Z)

Using .net 2003 to build my project.

Can someone examples to me what the link error means?
What is "__declspec(dllimport) public: class _STL::basic_ostream<char,struct _STL::char_traits<char> >" referring?
I already link in the stlport.lib library so I am not sure why I get this undefined symbols error.

Any help or hints on how to diagnostic this error would be appreciated.

thanks,
4eyes
Comment
Watch Question

>>>> What is "__declspec(dllimport) public: class _STL::basic_ostream<char,struct _STL::char_traits<char> >" referring?

basic_ostream is the STL class which was typedef'd to ostream and replaced old output stream class. basic_ostream is a template class (for switch between UNICODE strings and ANSI strings) which takes a char (ANSI) in your case and has a helper template class char_traits<char> which was used for allocation, comparision, and other stuff that differs between UNICODE char and ANSI char.

__declspec(dllimport) is a specifier which tells the compiler that the class' interface was imported from a dll (what doesn't matter as STL template classes were inline code as most - all - template classes).

Your problem is that Visual Studio has a own implementation of STL which is not compatible to that of STLPORT. You would need to fully switch off STL shipped with VC compiler and use STLPORT instead. That is makeable with some efforts but why? STL that came with VC7.1 is a good STL implementation that isn't less compliant to C++ standard than STLPORT. The latter was made to solve some issues of early implementations of STL (e. g. STL that came with VC6) but that is past in my opinion.

So, I would recommend to skip the STLPORT.

Regards, Alex

Author

Commented:
If I added using name space std in my cpp file, the unresolved symbols go away.
I have few dozen of cpp files, so I want to know if this is the only way can resolved this link error?

I tried to add the using namespace std; in the main header file, but it doesn't work,  So my guess is I must include the namespace in the cpp files individually?  Is this the only way?

My library is using the native stl, and it has been always working great for me.  However, I am working on a new project and need to include one of the library that use stlport.  and that's why I must include the stlport include header as well as the stlport library since I am also using that library header file.

Author

Commented:
Alex-

I tried to add using namespace std; or using namespace stlport; neither resolved the symobl issues.  Looks like I would have to use stlport, so what can I do to disable the native stl?
>>>> Looks like I would have to use stlport
Remove the path to stlport from the 'Additional Include Directories' in the project settings *and* in the include list found at Tools - Options - Projects - VC Folders.

Check the preprocessor macros in the Project settings whether they refer to STLPORT and remove them if they do.

Check the linker settings that there are o references to STLPORT either.

Note, it is much easier to get rid of STLPORT than to get rid of the VC STL ;-)  cause it is the default. If nothing helps create a new VC projects and add the sources of the old one. After that it should compile.

BTW, why do you think the above linker error was due to STLPORT? What do you exactly mean when saying "I link to the stlport library". Note, STL is a template class library what means that it contains out of header files only and it is *no* library involved.

Regards, Alex
>>>> I tried to add using namespace std;

The 'using namespace std; ' clause is only for the compiler that you can omit the std:: prefix when using STL classes and objects. It nothing has to do with the linker error.

The linker was missing an overloaded function of the global template function
 
        ostream& operator<<(ostream& os, ...)

I assume the ... means some io manipulators defined in <iomanip> header though it is really hard to analyse because of the weird syntax.

It is a good chance that stlport has a different implementation of that than VC stl, hence the linker error. But it also can be that the linker error is due to some restrictions that came with VC7 (means some changes in order to meet the C++ standard better than in the previous versions) and stlport has nothing to do with that.

You can try to comment statements which are using operator<< in test.cpp, e. g. a  'cout <<' in order to find the statement in your code that causes the link error. Comment one of these statements after the other until the linker error was gone.


Author

Commented:
Alex -

I >have to< use STLPORT, so I cannot remove the stlport in my "Additional Include Directories"

If I removed the "Additional Include Directories", it will compiler and links fine.  This is because my project was not design to use the STLPORT until now.

Why I need to use STLPORT?  Well, one of the module I need to integrate to my library uses stlport.  In order for me to integrate this new module, I need to include it's header file.  And in that header file or it's class, it uses stlport heavyly.  And that's why I added the stlport in my "additinoal Include Header".

Why I think the linker error is due to STLPORT?  well - because I always compile the library fine until I added the stlport in the "Additional Include Header" in my project.

Question - How can I force all ostream operator <<, >>, cout, cerr, cin to use stlport?  I tried to added using namespace stlport; but the linked error didn't go away.

Author

Commented:
Alex -

I did tried to comment it out the file that has the linker error.  Interesting, some of the file uses << operator but some of the files that doesn't even use the ostream operator and still shows the error.

Could it been a chain effect?
e.g. A.cpp uses the stl ostream
      B.cpp includes A.h
      C.cpp includes B.h

So if A.cpp has the linker error, so is B.cpp and C.cpp? I have about 100 files in my project so It will takes some time to verify this theory is correct or not.

Let me know what your thought is.  AND thanks for your help
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Alex -

I finally figured my problem.  In my include path, some of the stlport .inl files were missing so I am mixing both _STL and stlport and that's why I have the unresolved symbols.  

Thanks for your help anyway.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.