views:

157

answers:

4

Im wondering if anyone would be able to help me as I have been scratching my head for two days on this.

I have done the compilation and when trying to link a source code on linux getting undefined reference

Compiling using,

g++ -g -I/u01/kasunt/workspace/corelibCORBA/include -I/u01/kasunt/workspace/corelibCORBA/installed_components/include -I/u01/kasunt/workspace/corelibCORBA/idl -I/u01/kasunt/workspace/corelibCORBA/src/Server -I/u01/kasunt/workspace/corelibCORBA/installed_components/idl -I/u01/kasunt/workspace/corelibCORBA/installed_components/src/Server -I/u01/kasunt/workspace/corelibCORBA/installed_components/imake -DNARROWPROTO -I . -I/u01/kasunt/workspace/corelibCORBA/installed_components/include -W -Wall -Wpointer-arith -pipe -D_POSIX_THREADS -D_POSIX_THREAD_SAFE_FUNCTIONS -g -O -I/u01/kasunt/workspace/corelibCORBA/include -g -O -I/u01/kasunt/workspace/corelibCORBA/include -fvisibility=hidden -fvisibility-inlines-hidden -DACE_GCC_HAS_TEMPLATE_INSTANTIATION_VISIBILITY_ATTRS=1 -W -Wall -Wpointer-arith -ggdb -pipe -Wall -g -D_linux_ -D_x86_ -rdynamic -D_REENTRANT -DTAO_HAS_INTERCEPTORS=0 -DTAO_HAS_VALUETYPE=1 -D_REENTRANT -DACE_HAS_AIO_CALLS -D_GNU_SOURCE -I/usr/local/ACE+TAO+CIAO-5.7.9/ACE_wrappers -I/usr/local/ACE+TAO+CIAO-5.7.9/ACE_wrappers/TAO -I/usr/local/ACE+TAO+CIAO-5.7.9/ACE_wrappers/TAO/orbsvcs -DACE_HAS_EXCEPTIONS -D__ACE_INLINE__ -c -o TestSeqWrapper.o TestSeqWrapper.cpp

Linking using,

g++ -o TestSeqWrapper TestSeqWrapper.o -g -L/u01/kasunt/workspace/corelibCORBA/lib -L/u01/kasunt/workspace/corelibCORBA/installed_components/lib -g -O -Wl,-E -L/usr/local/ACE+TAO+CIAO-5.7.9/ACE_wrappers/lib -L/usr/local/ACE+TAO+CIAO-5.7.9/ACE_wrappers/lib -L/usr/local/ACE+TAO+CIAO-5.7.9/ACE_wrappers/TAO/tao -L/u01/kasunt/workspace/corelibCORBA/installed_components/idl -lcorelibCORBA -lcorelibCORBA /u01/kasunt/workspace/corelibCORBA/installed_components/lib/corelibCORBA3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/CorbaController3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/EConcurrency3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/corelibLogger3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/LeakTracker3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/trace3r.lib -lDefineTimeZone /u01/kasunt/workspace/corelibCORBA/installed_components/lib/timestamp3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/ApplConfig3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/appl3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/logstream3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/disklog3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/timeout3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/getpnam3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/config3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/strl3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/string3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/command3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/cmdargs3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/CppUtils3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/BuildTag3r.lib /u01/kasunt/workspace/corelibCORBA/installed_components/lib/exception3r.lib -lCorbaIdl -lTAO_Valuetype -lTAO_PortableServer -lTAO_IORTable -lTAO_AnyTypeCode -lTAO_CosEvent -lTAO_CosNaming -lTAO -lACE

TestSeqWrapper.o: In function `SeqWrapper':
/u01/kasunt/workspace/corelibCORBA/include/corelibCORBA/SeqWrapper.hpp:165: undefined reference to `ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T()'

Doing nm of the library I can see the above constructor is included,

nm --demangle ../installed_components/lib/libCorbaIdl.so | grep "ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T"
000327ba t ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T(ECONZ::Corba::ComboElementSeq_T const&)
000331c2 t ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T(unsigned int)
0002edb0 t ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T(unsigned int, unsigned int, ECONZ::Corba::ComboElement_T*, bool)
0002d768 t ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T()
00032e52 t ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T(ECONZ::Corba::ComboElementSeq_T const&)
0003172a t ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T(unsigned int)
0002d8e0 t ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T(unsigned int, unsigned int, ECONZ::Corba::ComboElement_T*, bool)
0002d8a6 t ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T()

Offending line on the source code (line 165), SeqWrapper() : var_( new SequenceType ), size_( 0 ) { }

Part of the code,

template< typename SEQUENCE >
class SeqWrapper : CppUtils::NonCopy
{
public:
   typedef SEQUENCE SequenceType;
   typedef typename SequenceType::_var_type SequenceType_var;

   typedef typename ElementTypeOf<SequenceType_var>::ElementType ElementType;
   typedef typename ElementTypeOf<SequenceType_var>::ReturnType ReturnType;
   typedef typename ElementTypeOf<SequenceType_var>::ConstReturnType ConstReturnType;

private:
   SequenceType_var var_;
   CORBA::ULong size_;

  void expand_( CORBA::ULong size )
  {
     // NOTE: current implementation assumes size only increases by small increments
     if (size > var_->length()) {
        var_->length( (size < 16)? 16 : (size > 256? size+256 : 2*size-2) );
     }
  }

public:
   SeqWrapper() : var_( new SequenceType ), size_( 0 ) { }
   SeqWrapper( CORBA::ULong reserve ) : var_( new SequenceType( reserve ) ), size_( 0 ) { var_->length( reserve ); }
   SeqWrapper( SequenceType *ownSeq ) : var_( ownSeq ), size_( ownSeq->length() ) { }

.....

Source code of TestSeqWrapper.cpp (I have removed most of the unwanted stuff to make it less confusing)

#include <iostream>
#include <CppUtils/StringHelpers.hpp>
#include <corelibCORBA/SeqWrapper.hpp>
#include <CorbaC.h>

using namespace std;

int main()
{
    ECONZ::Corba::SeqWrapper< ECONZ::Corba::StringSeq_T > seq;
}

And you can see that I have specified the shared library in the link options (shown in bold). I initially thought it might be due a dependency of some sort and moved the library flag to the beginning to no affect.

I appreciate it.

+1  A: 

Since you say

nm --demangle ../installed_components/lib/libCorbaIdl.so
> 0002d768 t ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T()

This means that ComboElementSeq_T() is in the lib -lCorbaIdl
If the reference is not being found, then it is being used by one of the libraries specified after this library:

> -lCorbaIdl -lTAO_Valuetype -lTAO_PortableServer -lTAO_IORTable
> -lTAO_AnyTypeCode -lTAO_CosEvent -lTAO_CosNaming -lTAO -lACE

Thus one of the follwoing contains : TestSeqWrapper.o: In functionSeqWrapper'`

  • -lTAO_Valuetype
  • -lTAO_PortableServer
  • -lTAO_IORTable
  • -lTAO_AnyTypeCode
  • -lTAO_CosEvent
  • -lTAO_CosNaming
  • -lTAO
  • -lACE

See: http://stackoverflow.com/questions/1095298/gcc-c-linker-errors-undefined-reference-to-vtable-for-xxx-undefined-referen/1095321#1095321

If you build all the libs as shared libraries then this problem goes away.

Martin York
I check all these libraries just to be sure. And none of them contain "ComboElementSeq_T" .... except for libCorbaIdl.so.
kuzyt
Even a simple link line such as this fails with the same errorg++ -L/u01/kasunt/workspace/corelibCORBA/installed_components/lib -lCorbaIdl -o TestSeqWrapper TestSeqWrapper.o
kuzyt
@kuzyt: You misunderstand. I am saying one of the other libraies is trying to use the symbol. The fact that it is defined only in -lCorbaIdl is what I expect. PS your second comment contains a different error message indicating you are missing a lib.
Martin York
Second linkage i did spits out the exact error message. It may be true that its pointing to a missing library but the fact that this is same error message as before kind of tells me this doesnt depend on other libraries isnt ? and the other libraries im linking are off the shelf ones from ACE/TAO. And "ComboElementSeq_T" within ECONZ::Corba is a custom written one.
kuzyt
@kuzyt: -llibrary should be after the object files. see OPTIONS general description in `man ld`
Dmitry Yudakov
Still nothing.g++ -o TestSeqWrapper TestSeqWrapper.o -L/u01/kasunt/workspace/corelibCORBA/installed_components/lib -lCorbaIdlTestSeqWrapper.o: In function `SeqWrapper':/u01/kasunt/workspace/corelibCORBA/include/corelibCORBA/SeqWrapper.hpp:165: undefined reference to `ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T()'
kuzyt
@Martin Just a quick question, but why is the gcc linker designed like this? Other linkers that I've seen from different toolchain doesn't care what order you specify them in as long as the symbol exist somewhere. This seems to me like an unnecessary implementation detail being exposed.
Victor T.
@Victor T: When linking static libs all linkers (that I have come across) work like this. It is to minimize the size of the application so that it only contains the code it actually requires to run.
Martin York
@Martin I just did a test on this to confirm and I can say that not all linkers have this ordering requirement -- at least for the ilink32 from borland and link.exe from MSVC9.What I did was setup 3 C::B projects: 1 dynamic called liba, 1 static called libb, and 1 console executable -- runner.exe. I switched the link order of liba and libb when building runner.exe and they all link fine under borland and msvc. But it does indeed fail to link under MinGW if liba comes before libb. I have C::B project files available if you want to confirm. 3 Targets setup one for each toolchain mentioned.
Victor T.
@Victor T. This only happens with statically linked libs (not dynamically linked which are completely different animals). Remove all dynamic libs and try with static libs only.
Martin York
@Victor T: PS. I am quite willing to believe that there are tool chains out there that do not behave in this exact manner :-) Every tool chain has its own quirks! even how symbols are resolved in dynamic libs at runtime can be quite interesting and spectacularly different.
Martin York
A: 

typo in your link line?

-L/u01/kasunt/workspace/corelibCORBA/idl

should be

-L/u01/kasunt/workspace/corelibCORBA/lib
Sam Miller
libCorbaIdl is within /u01/kasunt/workspace/corelibCORBA/installed_components/lib
kuzyt
So that linker path is not a typo? You might want to edit your question and clarify.
Sam Miller
"-L/u01/kasunt/workspace/corelibCORBA/lib -L/u01/kasunt/workspace/corelibCORBA/installed_components/lib"should be the path it searches for. "-L/u01/kasunt/workspace/corelibCORBA/idl" wasnt really a typo but rather an empty dir. I removed it for clarity. Thanx
kuzyt
A: 

Guys,

I dont know if this makes sense to anyone but seems that using library as a static instead of shared works perfectly. So I attached

/u01/kasunt/workspace/corelibCORBA/installed_components/lib/libCorbaIdl.a

and it worked perfectly. Anyone able to explain this ?????

kuzyt
could it possibly be a mangling problem on the shared library although i dont have any extern code anywhere
kuzyt
A: 

People,

After 10 cups of coffee and few almost sleepless nights I managed to get to the bottom of the problem. Hopefully this helps someone and someone will be able shed some light into me about avoiding such things. So here goes.

I ran the following once again with the -D option this time and it showed a completely different output and one that I was kind of expecting. It resulted in nothing and "ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T" was not found.

nm -DC ../installed_components/lib/libCorbaIdl.so | grep "ECONZ::Corba::ComboElementSeq_T::ComboElementSeq_T"

Then it sort of led me to believe a compilation problem with the lib. So I looked closely into the compiler flags and found these two "-fvisibility=hidden -fvisibility-inlines-hidden". This was coming from ACE/TAO and it was a new attribute they have added since GCC 4. This was causing the dynamic symbols to be hidden. So my question for anyone who is aware of this is what I should have done to link the library ?

For further reading please read http://gcc.gnu.org/wiki/Visibility

kuzyt