Reputation: 33
I am using ACE6.0.2 on a Suse 11 x86 machine.The version of gcc is 4.3 and ACE-TAO lib has been compiled with no problem.
The test I wanted to do is very simple but it just can't pass.
I have three files. a1.h defines a class A.
class A
{
public:
A();
void print();
};
a1.cpp has a function invoking the method from ACE lib.
#include "a1.h"
#include <ace/Thread.h>
#include <iostream>
A::A(){}
void A::print()
{
long t=ACE_Thread::self();
std::cout<<t<<std::endl;
}
main.cpp invokes print() from class A
#include "a1.h"
int main()
{
A a;
a.print();
return 0;
}
The compiling command I used is:
1.generate a1.o with ACE_thread
g++ -c -fPIC -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -O3 -ggdb -pthread -Wall -W -Wpointer-arith -pipe -D_GNU_SOURCE -I/opt/ACE_wrappers -DACE_HAS_VALGRIND -D__ACE_INLINE__ -I.. -Wl,-E -L/opt/ACE_wrappers/lib -L. -o a1.o a1.cpp
2.generate shared libT.so
g++ -pthread -Wl,-O3 -shared -o libT.so a1.o -Wl,-E -L/opt/ACE_wrappers -L. -L/opt/ACE_wrappers/lib -lACE -ldl -lrt
3.generate main.o
g++ -c -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -O3 -ggdb -pthread -Wall -W -Wpointer-arith -pipe -D_GNU_SOURCE -I/opt/ACE_wrappers -DACE_HAS_VALGRIND -D__ACE_INLINE__ -I.. -Wl,-E -L/opt/ACE_wrappers/lib -L. -o main.o main.cpp -lACE -ldl -lrt
4.link and generate the executable file
g++ -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -O3 -ggdb -pthread -Wall -W -Wpointer-arith -pipe -D_GNU_SOURCE -I/opt/ACE_wrappers -DACE_HAS_VALGRIND -D__ACE_INLINE__ -I.. -Wl,-E -L/opt/ACE_wrappers/lib -L. -o main main.o -lT -lACE -ldl -lrt
The problems occurred at step 4:
main.o: In function `main':
/main.cpp:5: undefined reference to `A::A()'
/main.cpp:6: undefined reference to `A::print()'
I am new to C++ under linux and don't understand why this happens. There must be something wrong with my compiling commands.Thanks for help in advance.
Upvotes: 2
Views: 1808
Reputation: 1
Thanks user1349058! After a lot of hours researching, luckily I found your comment and it works perfectly.
For example, the command I used when building ACE library 32-bits on Linux is:
$ make static_libs=1 buildbits=32 no_hidden_visibility=1
$ make install
Upvotes: 0
Reputation:
Well, you have just enabled -fvisibility=hidden
flag which makes all symbols hidden by default. As a result, your class A
is not visible to anything outside the shared library you have compiled.
There are two solutions:
-fvisibility=hidden
flag. This will make all symbols visible by default.A
class (and pretty much everything else that you want to access in your shared library from "the outside world") as public. This is compiler-specific and is usually done with macros. For more information on gcc, see GCC Visibility Wiki.Just to make it clear, this issue is yours and yours only. It has absolutely nothing to do with Ace or any other library.
Hope it helps. Good Luck!
Upvotes: 0