PDA

View Full Version : adding a library to my project and..how to use it?



KillGabio
30th January 2012, 19:00
hi guys i ve read tons of threads of this problem but i dont seem to get the right solution...

i ve downloaded the qextserialport-1.2 project. Next step i run the project with errors (says no executable found, of course because its not an app) but i get the files:

qextserialport.dll
libqextserialport.a

then i create a folder inside myappfolder and finally i modify my .pro file like this

INCLUDEPATH += "C:\Documents and Settings\home\Escritorio\Los taninos-killgabio\exrport-libraries"

LIBS += -L"C:\Documents and Settings\home\Escritorio\Los taninos-killgabio\exrport-libraries" -lqextserialport

what is the next step to follow? cause there are no .h files, or should i include all the .h files from the qextserialport project¨?

thanks a lot i ve started a month ago and i still cannot understand QT very much :(

greetings!

ChrisW67
30th January 2012, 21:30
Checkout and build the current qextserialport (http://code.google.com/p/qextserialport/):
The "src" directory of the qextserialport source tree contains the include files: put this path in INCLUDEPATH
The "src/build" directory of the qextserialport source tree contains the library files: put this in the -L option of LIBS

If you have grabbed the obsolete version (http://sourceforge.net/projects/qextserialport/):
The "qextserialport-1.2win-alpha" directory of the qextserialport source tree contains the include files: put this path in INCLUDEPATH

KillGabio
30th January 2012, 23:18
so i downloaded the current version, build it with errors again (same old: no executable file especified) but i can actually include the libs generated and i can use the classes inside the src. Next step i try to prove it by doing this:


QList<QextPortInfo> ports = QextSerialEnumerator::getPorts ();
/* qDebug() << "SerialSettings::LoadPorts(): List of ports availables:\n";
for (int i = 0; i < ports.size(); i++) {
qDebug() << "port name: " << ports.at(i).portName;
qDebug() << "friendly name: " << ports.at(i).friendName;
qDebug() << "physical name: " << ports.at(i).physName;
qDebug() << "enumerator name: " << ports.at(i).enumName;
qDebug() << "===================================";
}*/
Declaring that sentence provoques a segmentation fault ((The program has unexpectedly finished. exited with code -1073741819))

So the problem is in the libraries i included right? I dont get it :( sorry

Added after 19 minutes:


QextSerialEnumerator *one = new QextSerialEnumerator ();
QList<QextPortInfo> ports = one->getPorts ();

if i change it like this, i get the following errors:


error: undefined reference to `_imp___ZN20QextSerialEnumeratorC1Ev'
error: undefined reference to `_imp___ZN20QextSerialEnumerator8getPortsEv'

ChrisW67
31st January 2012, 06:10
so i downloaded the current version, build it with errors again (same old: no executable file especified) but i can actually include the libs generated and i can use the classes inside the src.
How are you building it? You are clearly doing something wrong. The steps are:

Unpack or checkout the source
Open command shell with the Qt environment set up.
cd {sourcedir}
qmake
mingw32-make (or nmake for MSVC)





QextSerialEnumerator *one = new QextSerialEnumerator ();
QList<QextPortInfo> ports = one->getPorts ();

if i change it like this, i get the following errors:

Then your LIBS variable is set wrong in your application's PRO file or there are no libraries being built.

KillGabio
31st January 2012, 14:39
Excuse me if im very newbie...but what`s the difference between opening the source .pro file, running qmake and then building it?

I followed your steps , but when run the code of my i get the same errors



error: undefined reference to `_imp___ZN20QextSerialEnumeratorC1Ev'
error: undefined reference to `_imp___ZN20QextSerialEnumerator8getPortsEv'


then i try to open the project for qextserialport (called src.pro) and i get the same error: no executable especified. I dont know why if in the build folder i have the libraries it doesnt work...

ChrisW67
31st January 2012, 23:15
The source code for qextserialport contains the pro file called qextserialport.pro. This project builds the src directory and the examples. The src directory is configured to build a library. If you try to Run, rather than Build, the library in Qt Creator of course it will fail: there's no executable to run.

If those errors are coming from the linking stage of building your program, as I suspect, then your LIBS variable is wrong.

If the program builds successfully and those errors are issued when you try to run your compiled program then the dynamically loaded libraries are not being found by system. On Windows they need to be in the system PATH or the same directory as your executable. These are not typical Windows error messages for broken runtime dependencies.

KillGabio
1st February 2012, 00:26
Sweet Lord i hate being so ignorant, i figured that out before you answer (the problem with the executable) but the thing is that i still cannot make it work.

i have this in my .pro


INCLUDEPATH += "C:/Documents and Settings/home/Escritorio/Los taninos-killgabio/qextserialport/src"

INCLUDEPATH += "C:/Documents and Settings/home/Escritorio/Los taninos-killgabio/GestionVinoteca/include" //this has nothing to do

LIBS += -L"C:/Documents and Settings/home/Escritorio/Los taninos-killgabio/qextserialport/src/build"


and in the folder specified i have:
* libqextserialportd1.a
* qextserialportd1.dll

i also copied that dll to the folder of my app just in case. The headers are being found because the moment i type "qex.." all the headers from src folder are suggested. But when i try to execute the code i get the same error (error: undefined reference to `_imp___ZN20QextSerialEnumerator8getPortsEv' )...sorry for wasting your time like this but im so loosing my head

Added after 42 minutes:

i changed the LIBS variable to this:



LIBS += -L"C:/Documents and Settings/home/Escritorio/Los taninos-killgabio/qextserialport/src/build" -lqextserialportd1


Even though the library is called "libqextserialportd1.a" i can only compile the application by putting the way i just described.

So the program compiles with no errors BUT now i get this error:


The program has unexpectedly finished.

like a segmentation fault I dont really know while trying to do this:


qDebug () << "say hi!!";
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
qDebug() << "List of ports:";
for (int i = 0; i < ports.size(); i++) {
qDebug() << "port name:" << ports.at(i).portName;
qDebug() << "friendly name:" << ports.at(i).friendName;
qDebug() << "physical name:" << ports.at(i).physName;
qDebug() << "enumerator name:" << ports.at(i).enumName;
qDebug() << "vendor ID:" << QString::number(ports.at(i).vendorID, 16);
qDebug() << "product ID:" << QString::number(ports.at(i).productID, 16);
qDebug() << "===================================";
}


no words ""say hi!!" printed on the application output so i cannot figure what`s the real problem :S

ChrisW67
1st February 2012, 00:27
You have told the linker where to look for libraries (-L), but not which library to look for and link ( -l, you had that in your first post).


LIBS += -L"C:/Documents and Settings/home/Escritorio/Los taninos-killgabio/qextserialport/src/build" -lqextserialport

(Assumes a release build of qextserialport)

KillGabio
1st February 2012, 00:36
i think what you meant is what i changed, right? have a look at my last edit sorry :crying:

ChrisW67
1st February 2012, 00:52
Look in the library directory: do you see a file qextserialportd1.dll? I seriously doubt that the library is called qextserialportd1. Remove the "1".

There are two flavours of library on Windows. If you build a library in release mode you get something.dll and in debug you get somethingd.dll. Depending on exact circumstance they may also be in different directories. If you built a release version of the qextserialport library (the default) then also remove the trailing "d" in the LIBS line.

KillGabio
1st February 2012, 01:46
yes sir, I see a qextserialportd1.dll in my library directory, i can send you a picture lol. I removed the d1 from both the .a and .dll file and changed my .pro file...but segmentation fault again :(

wysota
1st February 2012, 01:47
Do you get any error number?

KillGabio
1st February 2012, 02:17
-1073741515 <---EROR number


Starting C:\Documents and Settings\home\Escritorio\Los taninos-killgabio\GestionVinoteca-build-desktop\release\GestionVinoteca.exe...
The program has unexpectedly finished.
C:\Documents and Settings\home\Escritorio\Los taninos-killgabio\GestionVinoteca-build-desktop\release\GestionVinoteca.exe exited with code -1073741515

Added after 17 minutes:

if i change the file names without the d1 i get DLL not found when i run it in debugging mode

ChrisW67
1st February 2012, 02:33
Search this forum for "-1073741515" and you will find it a few times, usually with the same solution. Also, -1073741515 = 0xC0000135: If you Google that you will find that it means that the program failed to initialise, i.e. it isn't even loading. Make sure everything it needs in the way of dynamically loaded libraries are available (probably missing qextserialportd.dll in your system path or application directory).


yes sir, I see a qextserialportd1.dll in my library directory,
Exactly what qextserialport code are you building?

The code from Mercurial (http://code.google.com/p/qextserialport/source/checkout) does not build at all for me.

I just grabbed the older package from Sourceforge (http://sourceforge.net/projects/qextserialport/), unpacked it, ran qmake and mingw32-make (Qt 4.7.3) The library built with a single low-level warning. The build subdirectory:


Y:\qextserialport-1.2win-alpha>dir build
Volume in drive Y is VBOX_tmp
Volume Serial Number is 0000-0822

Directory of Y:\qextserialport-1.2win-alpha\build

01/02/2012 12:17 PM 104,490 libqextserialportd.a
01/02/2012 12:17 PM <DIR> moc
01/02/2012 12:17 PM <DIR> obj
01/02/2012 12:17 PM 1,010,605 qextserialportd.dll
2 File(s) 1,123,287 bytes
2 Dir(s) 83,275,481,088 bytes free

If I build in release mode I get the same without the "d" suffix.

KillGabio
1st February 2012, 02:45
As i couldnt download the current version, as you proposed in your first answer, what i did was to browse the code, create the files and copy all the code lines to my files (conserving original names and everything). Actually i knew what the error was talking about, but as i couldnt fix it i copied the libs and dll to almost every folder contaning information either of my project or Qt itself. I`m now starting from zero deleting everything, and in a while i ll let you know how it goes. Thanks in advance, i ll like to have you and wysota right by my side programming with me lol.

wysota
1st February 2012, 02:55
Thanks in advance, i ll like to have you and wysota right by my side programming with me lol.

If the salary is right, we can talk about it ;)

KillGabio
1st February 2012, 03:00
I copied the dll file to this location i added to my app


a.addLibraryPath (a.applicationDirPath ()+ "/plugins");


and voilaa:



say hi!!
List of ports:
port name: "COM1
friendly name: "Puerto de comunicaciones (COM1)"
physical name: "\Device\00000066"
enumerator name: "ACPI"
===================================


guess the """current version""" isnt friendly with Qt :/ still what i need to know is right there :D

THANKS A LOT!! You are being very helpfull guys and i really appreciate that, i`m trying to help other people here in the forum but unluckly my knowleadge is not so vast.

Greetings from Argentina!!

ChrisW67
1st February 2012, 05:17
I copied the dll file to this location i added to my app


a.addLibraryPath (a.applicationDirPath ()+ "/plugins");


Then you should have been able to copy it to the directory above that (i.e. next to the executable) and not had to modify your code.


Thanks in advance, i ll like to have you and wysota right by my side programming with me lol.
The salary would have to be right, and 100% telecommuting too I guess... otherwise the 30 hour one-way commute time would be a problem. ;)

KillGabio
1st February 2012, 15:37
Then you should have been able to copy it to the directory above that (i.e. next to the executable) and not had to modify your code.

Funny how i tested deleting that line and putting the dll next to the executable and it didnt work :( (I also put it right next to it :P)



The salary would have to be right, and 100% telecommuting too I guess... otherwise the 30 hour one-way commute time would be a problem. ;)

I`m just doing an app for my family as a "hobby", i need to finish the university first to start talking about hiring people, lol, but it would be nice to work with such helpfull people :D

wysota
1st February 2012, 19:43
I got a bit confused here. Does qextserialport use plugins? How are you loading the library? Because addLibraryPath() has no influence on libraries linked using LIBS+= -lsomething since it's executed long after the shared object is being loaded.

KillGabio
1st February 2012, 20:02
All you say is correct, but you need to have the .dll file somewhere the application finds it. So as placing it where my .exe is located didnt work I have to add that path so that the application look there for the .dll files.

Maybe my English is so bad you didnt understand me :P

ChrisW67
1st February 2012, 21:31
@wysota: Qextserialport is not implemented as a plugin. It is a standard dynamic library, automatically linked at start-up (or optionally a static library).

@Killgabio: Your English is understandable. Your description of exactly what is going on on your machine is probably not complete or accurate because your "solution" does not make technical sense. If we don't get to the bottom of this then you will be back in a while asking why you cannot get your program to run on another, non-development, machine.

Can I suggest that your search your entire machine for copies of qextserialport.dll and qextserialportd.dll and remove all except the copy in your qextserialport build directory. Confirm that your program no longer runs. Then copy the DLL from the qextserialport build directory to the location that yourprogram.exe is in (this is probably not the same place as your source code). Confirm that your executable now runs.

A deployed application (Windows) should ultimately look like:


Program Files/
My Program/
myprogram.exe
qextserialport.dll // your program's shared components (not plugins)

mingwm10.dll // for MingW GNU C++ programs
libgcc_s_dw2-1.dll

qtcore4.dll // Your required Qt components
qtgui4.dll
...
sqldrivers/
qsqlite4.dll
...
imageformats/
qjepg4.dll
...

On your dev machine the Qt and MingW components should be found without copying them, but your program's other shared components will not be found by default.

KillGabio
1st February 2012, 21:56
now i don`t need to add the plugins path anymore. I was just confusing things sorry!

Thanks a lot!


PS: Actually all the .dll you mentioned i have allready placed them on me release folder because every two days im testing the advances of the application on another computer, untill today everything was fine but now i cannot understand how to use this other library i downloaded, it driving me crazy actually. If you can have a look (http://www.qtcentre.org/threads/47142-General-Advice)when you have time i ll be pleased :D think that is going to be one of my last problems :/ greetings!