Qt creator use .so in linux
-
wrote on 13 Dec 2011, 10:47 last edited by
I want to use qt creator binding the .so generated by matlab in linux.
It will be great to show me a simple example of how qt using the .so generated by matlab.
Many thanks! -
wrote on 13 Dec 2011, 10:50 last edited by
Qt Creator usually uses qmake to build its stuff, so I have to refer you to "the qmake documentation":http://doc.qt.nokia.com/latest/qmake-variable-reference.html#libs.
-
wrote on 13 Dec 2011, 12:10 last edited by
Section "Declaring Other Libraries" of the "qmake Project Files":http://developer.qt.nokia.com/doc/qt-4.7/qmake-project-files.html manual has an example on how to use external libraries in your project.
-
wrote on 14 Dec 2011, 13:44 last edited by
When I try to open a shared library **.so,Qt Creator shows this mistake:
Fatal error: cannot get path to runtime module.[quote author="Volker" date="1323778201"]Section "Declaring Other Libraries" of the "qmake Project Files":http://developer.qt.nokia.com/doc/qt-4.7/qmake-project-files.html manual has an example on how to use external libraries in your project.[/quote]
-
wrote on 17 Dec 2011, 00:28 last edited by
Where do you "open" a shared library in Creator?
-
wrote on 17 Dec 2011, 10:06 last edited by
@
void *handle;
void (*myfun)(void);
char *error;handle = dlopen ("libadd.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
}dlerror();
*(void **) (&myfun) = dlsym(handle, "add");dlerror();
(*myfun)();
dlclose(handle);@
[EDIT: code formatting, Volker]
-
wrote on 18 Dec 2011, 00:47 last edited by
Ah, you try to open it in your own application and you see a runtime error message in Creator's output tabs, now I understand.
Hm, seems as if dlopen doesn't know where to search for your .so - you'll have to use your OS' methods for search paths or use an absolute path.
Did you consider using [[Doc:QLibrary]] to replace dlopen?
-
wrote on 18 Dec 2011, 06:19 last edited by
@
typedef int (*MyPrototype)(int,int);
MyPrototype myFunction =
(MyPrototype) QLibrary::resolve("/home/liu111/123/libadd.so", "add");
int aa=myFunction(0,1);
@these codes stops:int aa=myFunction(0,1)
and Ccreator says :"The program has unexpectedly finished."
But it works very well for the .so provided by MATLAB,like libm.so,and I have tested "cos" from libm.so ,and it works very well. The libadd.so is generated by the libadd.m which is written by myself.The method generating .so from .m works perfectly usder win32,maybe the above problem is caused by MATLAB does not coordinate with linux perfectly. -
wrote on 18 Dec 2011, 14:06 last edited by
Please wrap your code in @-tags to get pretty formatting.
Is your library made of C-code or of C++? The latter does not work with resolve.
-
wrote on 19 Dec 2011, 00:34 last edited by
My library is made of Matlba-code . Matlab can generate *.so from *.m .
Thank you very much. -
wrote on 19 Dec 2011, 12:53 last edited by
Sorry, I have no idea how matlab creates its libraries; I'm out here. Maybe someone in a matlab forum can be of better help, as it doesn't seem to be a Qt problem, but more one of interfacing matlab libs with C++ code.
1/11