I want to use one .dll file in another. But it seems like I'm doing something wrong with it. I have two library project ScaraControlGUI and ScaraLogic, and I want to use ScaraLogic into ScaraControlGUI, so I added appropriate lines in ScaraControlGUI's .pro file:
DEPENDPATH += . ../ScaraLogic
INCLUDEPATH += ../ScaraLogic
LIBS += -L../ScaraLogic/debug -lScaraLogic
And I receive:
scaralogic.h: No such file or directory
When I want to include this file. I'm sure that this file exist so I bet that I'm doing something wrong around .pro files.
What I'm doing wrong ? Adding ScaraControlGUI .dll to main executable project works fine like this.
Thanks in advace for help.
As your header is in ScaraLogic/Headers directory, you have to include it as #include <Headers/scaralogic.h>, or, which is better, set INCLUDEPATH as
DEPENDPATH += . ../ScaraLogic
INCLUDEPATH += ../ScaraLogic/Headers
LIBS += -L../ScaraLogic/debug -lScaraLogic
in the project file, and still use #include <scaralogic.h>.
I resolved my problem. My ScaraControlGUI subproject was building properly. Problem was in my main project ScaraControl and to solve this I needed to add LIBS and INCLUDEPATH too.
Related
My questions may seems like it is a real duplicate, but however I checked many related questions, my problem still remains.
I found and compiled a project called SMTPEmail, so I have my .dll and .lib files under the directories Libraries/SMTPClient/debug and Libraries/SMTPClient/release.
When I try to include the header files in example in case of emailadress.h: #include <emailaddress.h> or #include <SMTPEmail/emailaddress.h>, I got the error Cannot open include file 'emailaddress.h'. The Q_DECL_EXPORT modifier is used in the header files.
SMTPEmail.pro:
...
QT += core network
TARGET = SMTPEmail
TEMPLATE = lib
DEFINES += SMTP_BUILD
win32:CONFIG += dll
QMAKE_CXXFLAGS += -fPIC
...
MyProject.pro:
...
INCLUDEPATH += ./Libraries/SMTPClient/debug
DEPENDPATH += ./Libraries/SMTPClient/debug
win32:LIBS += ./Libraries/SMTPClient/debug/SMTPEmail.lib
...
I also tried:
LIBS += -L./Libraries/SMTPClient/debug/ -lSMTPEmail
and
LIBS += -L$$_PRO_FILE_PWD_/Libraries/SMTPClient/debug/ -lSMTPEmail
and
LIBS += -L$$PWD_/Libraries/SMTPClient/debug/ -lSMTPEmail
and
LIBS += -L./MyProject/Libraries/SMTPClient/release/ -lSMTPEmail
The only thing that I didn't do is copying or linking the header files which are inside the library to my app?
I have the strong feeling that I missed a small step somewhere, can you help me pointing out what I am doing wrong?
I think your problem is (at least) this line:
INCLUDEPATH += ./Libraries/SMTPClient/debug
I am almost certain that this is not the right path to the include path where the headers can be found including emailadress.h.
You have explained the LIBS values that you have tried as well as the lib path in great length, but you are getting an include error from the compiler rather than a linkage problem with the libraries from the linker. I would suggest to figure out where the headers are located and add it to the include path as follows:
# This is just pseudo code, but you need something like this
INCLUDEPATH += $$PWD/Includes/SMTPClient
Answering your question of:
The only thing that I didn't to is copying the header files which should be inside the library, is that right?
It depends on what you mean. If you mean whether the library should be self-contained, then the answer is no, unless you are using dynamic library loading with manual symbol resolution and the like, which I do not recommend for simple cases.
If you mean, it is shipped with the project that you are trying to reuse, then sure, and that is why you would need to specify the includepath in your project to that path.
I am trying to link winpcap into my QT creator project.
For that I've added this to my .pro file:
INCLUDEPATH += C:/WpdPack/Include
LIBS += -LC:/WpdPack/Lib -lwpcap - lpacket
When I type #include <pcap.h> the code assistant autocompletes but on compile I get Error:C1083: Cannot open include file: 'pcap.h': No such file or directory.
Any help would be very appreciated.
Typically the solution pops up after asking the question:
I've found a workaround
INCLUDEPATH += C:/WpdPack/Include
LIBS += C:/WpdPack/Lib/wpcap.lib
LIBS += C:/WpdPack/Lib/Packet.lib
CONFIG += no_lflags_merge
And it builds.
Let me start off by saying I'm fairly new to Qt. That being said, I'm having dependency issues.
I am trying to use mclmcrrt.h in the Matlab directory. From my *.pro file I right click->add library->external library->browse, etc. and I get the following:
win32: LIBS += -L$$PWD/../../../Program Files (x86)/MATLAB/MATLAB Compiler Runtime/v714/extern/lib/win32/microsoft/ -lmclmcrrt
INCLUDEPATH += $$PWD/../../../Program Files (x86)/MATLAB/MATLAB Compiler Runtime/v714/extern/include
DEPENDPATH += $$PWD/../../../Program Files (x86)/MATLAB/MATLAB Compiler Runtime/v714/extern/include
This looks similar to what I've seen in other places using the INCLUDEPATH, etc. Also, in my included header file that's calling mclmcrrt.h I have:
#include "mclmcrrt.h"
No matter what, I can't get rid of the error: "mclmcrrt.h: No such file or directory"
I looked around and tried a lot of things. I got this working in Visual Studio, but can't seem to get it here.
Thanks in advance!
Spaces in paths break the parser, try this:
win32: LIBS += -L$$PWD/../../../"Program Files (x86)/MATLAB/MATLAB Compiler Runtime"/v714/extern/lib/win32/microsoft/ -lmclmcrrt
INCLUDEPATH += $$PWD/../../../"Program Files (x86)/MATLAB/MATLAB Compiler Runtime"/v714/extern/include
DEPENDPATH += $$PWD/../../../"Program Files (x86)/MATLAB/MATLAB Compiler Runtime"/v714/extern/include
I am trying to use and make a DLL in Qt. The DLL, does not use any Qt frameworks. Here is my library's .pro file:
TARGET = MyLib
TEMPLATE = lib
include(Botan.pri)
win32:INCLUDEPATH += "C:/botan/include"
win32:LIBS += "C:/botan/libBotan.a"
unix:INCLUDEPATH += "/usr/local/include/botan-1.10"
unix:LIBS += "/usr/local/lib/libbotan-1.10.a"
HEADERS += \
HEADERS HERE
SOURCES += \
SOUCRES HERE
My library is compiled successfully, and I get a MyLib.dll in my debug/release folder. I then copied my library sources completely, and removed everything besides the header files for the 'includes' folder.
I then created a new project to use my library.
I added this to my project file:
INCLUDEPATH += "C:/Users/Stevie/Desktop/MyLib/include"
LIBS += "C:/Users/Stevie/Desktop/MyLib/MyLib.dll"
The headers have no problem, and it finds my DLL fine (if I change it to a non-existing path, it throw an error. It doesn't as of now.)
Now when I go into my '.cpp' file, I include my header file, and try and use my library and it throws 'undefined reference to MyLib::...'. I have no idea why, as I am including the DLL and I believe it should be found perfectly fine.
Also, I am 99% sure it isn't with Botan, as I use Botan often like this, and it works fine. Anyway, I include the 'Botan.dll' with it anyway just to be sure, but it's not throwing the undefined errors on Botan.
Thanks.
Replace
LIBS += "C:/Users/Stevie/Desktop/MyLib/MyLib.dll"
with
LIBS += -L$$quote(C:/Users/Stevie/Desktop/MyLib)
LIBS += -l$$quote(MyLib)
Does your library have Q_DECL_EXPORT / Q_DECL_IMPORT macros?
After all that clean and rebuild your project, which use library.
I'm quite a newbie with C++ and maybe that's a very stupid question, but how do one include a header from a static linked library?
I've created a static library in Qt Creator with the following .pro file:
QT -= gui
TARGET = Foobar
TEMPLATE = lib
CONFIG += staticlib
SOURCES += thefoobar.cpp \
sub/subbar.cpp
HEADERS += thefoobar.h \
sub/subbar.h
compiled it and put the resulting libFoobar.a into the "extstaticlibs" folder of my target project.
In my target projects .pro file i've added the following lines:
LIBS += -L$$PWD/extstaticlibs/ -lFoobar
INCLUDEPATH += $$PWD/extstaticlibs
The target project compiles without problems. But when I try to include the header thefoobar.h in one of my code files:
#include "thefoobar.h"
it always results in an error:
error: thefoobar.h: No such file or directory
Any suggestions for the correct syntax would be very much appreciated.
Kristoffer
Check where you have placed your "thefoobar.h" header file . Place it in the "extstaticlibs/" folder .
If I follow your description correctly, you ONLY put the static library into your extstaticlibs directory.
You need to carry over your thefoobar.h file too. If you follow the common structure you could make:
extstaticlibs/include <- thefoobar.h goes here
extstaticlibs/lib <- libFoobar.a goes here
You then need to modify your project file like this:
LIBS += -L$$PWD/extstaticlibs/lib -lFoobar
INCLUDEPATH += $$PWD/extstaticlibs/include
Of course you can all throw it in one directory, if you want, but it may be helpful to sort things out in the beginning.