PDA

View Full Version : Static Linking Issue WinXp MingW 4.5.1 Qt 4.7.1(static compiled)



cafu1007
31st May 2011, 15:07
Hi there,

Has anybody experience problem while developing static libraries, with this setup?

It seems that i have linking problem when i used a function within a library class "lib1" that use a function funLib2 within another library "lib2"(something like a wrapper library). if i called the lib1 fuction directly from the exe it is ok, but if called thru lib2 the linker says undefined reference.



class lib1
{
public:
void func1()
{
}
}
class lib2
{
public:
void func2()
{
func1();
}
}
class exeClassWorking
{
exeClass()
{
func1();
}
}

class exeClassWorking2
{
exeClass()
{
func1();
func2();
}
}
class exeClass_NOT_Working
{
exeClass()
{
func2();
}
}


I hope i could be clear, anyway i will be glad to detailed more in case needed.

in all cases both lib have been include in the pro file.

Any of this approach works when i compiled as shared.

jeanremi
31st May 2011, 18:18
It's very clear.

How do your classes see each other's function objects ?

Basically, be a bit more detailed.... maybe we can see what's missing?

cafu1007
1st June 2011, 12:19
sorry i forgot to specified that the function are static(s)

jeanremi
1st June 2011, 16:32
OK well from what you've just said: This problem has nothing to do with Qt.
It's a C++ problem.
You need to understand that you cannot call a static function from your second library.
Static functions are only accessible from within modules where they are declared and defined NOT accross library boundaries. That's why your exe can see it but your lib2 can't.
IF you want to access this function from your second lib, you need to export it.

I suggest you go read about how to export C++ functions/classes (if you haven't already done so).

Alternatively, ask your question in any C++ forum, but it's not for here (No pun intended)

Best of luck.

Jean