Unreferenced Libraries?
-
Alright,
I am having a lot of trouble correctly linking libraries to QT 4. I created a simple library called test_class and here is the code:
test_class.cpp
@
#include "test_class.h"int test_me::whatever(void)
{
return 5;
}
@test_class.h
@
#ifndef TEST_CLASS_H
#define TEST_CLASS_Hclass test_me
{
public:
int whatever(void);
};#endif
@I then create that into a .lib and try to call it from my other program in this manner:
@
MainWindow.cpptest_me abc; abc.whatever();
@
I have the proper include in MainWindow.cpp and I have the library in my .pro file correct. Any ideas? I'm getting this as an error:
Quoted mainwindow.cpp:26: error: undefined reference to `test_me::whatever()' :-1: error: collect2: ld returned 1 exit status
-
[quote author="Lukas Geyer" date="1313072764"][quote author="JediSpam" date="1313071868"]I then create that into a .lib[/quote]
Are we talking about a static library or a shared library? If so you will have to export symbols as loladiro said.[/quote]
this is a static library i have created in visual studio 2003. i'm trying to understand the library template stuff
-
You talking about static library ?
-
[quote author="loladiro" date="1313072534"]You are not exporting the class.
If you are using Qt Creator, have a look at the library template.[/quote]I read the qMake Project Files section "Declaring Other Libraries" and don't see what I haven't done correctly.
[quote author="Lukas Geyer" date="1313072949"]You might use the nm tool to see which symbols are exported from your library.[/quote]
Is this a QT tool I don't see it anywhere
-
[quote author="loladiro" date="1313076573"]Again, did you compile your library with mingw? It doesn't seem that way because mingw static library files have a .a extension. You cannot mix MSVC and MinGW.[/quote]
ah i see. so i'd have to use the MinGW in visual studio to build a library.
-
[quote author="JediSpam" date="1313076335"]
[quote author="Lukas Geyer" date="1313072949"]You might use the nm tool to see which symbols are exported from your library.[/quote]
Is this a QT tool I don't see it anywhere
[/quote]nm comes with MinGW, which is part of the Qt SDK. Just open a Qt command promt and type nm <binary> to get a list of exported symbols.
(Although it comes with MinGW it should work with any PE - read MSVC - binaries).