LNK1146: no argument specified with option '/LIBPATH:' error in Qt - c++

I imported my Qt application developed on linux to windows. Now when I build my project I am getting this error:
error: LNK1146: no argument specified with option '/LIBPATH:'
I created a new project on windows and it works perfectly fine. One of the possible reason that would cause this is having spaces in the project path,but there are no spaces in my project path.Could you let me know how I could resolve this issue.
This is my .pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2014-12-08T09:19:31
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = FirstProject
TEMPLATE = app
QMAKE_CXXFLAGS += -std=c++11
SOURCES += main.cpp\
firstscreen.cpp \
secondscreen.cpp \
thirdscreen.cpp
INCLUDEPATH += C:\Users\user_name\tango\ \
C:\Users\user_name\omniORB4\ \
C:\Users\user_name\omnithread.h
HEADERS += firstscreen.h \
C:\Users\user_name\tango\ \
C:\Users\user_name\omniORB4\ \
C:\Users\user_name\omnithread.h \
secondscreen.h \
thirdscreen.h
LIBS += -L -lomnithread \
-L -lomniORB4 \
-L -ltango
FORMS += firstscreen.ui \
secondscreen.ui \
thirdscreen.ui

The problem happens because the flag -L was specified, but no library paths were given:
LIBS += -L -lomnithread \
-L -lomniORB4 \
-L -ltango
To fix this problem, you must provide the paths where the .lib files are located, which would be something like:
LIBS += -L"C:\\Users\\user_name\\omnithread\\lib" -lomnithread \
-L"C:\\Users\\user_name\\omniORB4\\lib" -lomniORB4 \
-L"C:\\Users\\user_name\\tango\\lib" -ltango
Remember: there must be no empty spaces between -L and the path string.
So doing it like this will also throw the same error:
LIBS += -L "C:\\Users\\user_name\\omnithread\\lib" -lomnithread \
-L "C:\\Users\\user_name\\omniORB4\\lib" -lomniORB4 \
-L "C:\\Users\\user_name\\tango\\lib" -ltango

In your .pro file the problem is probably the empty "-L" when assigning to LIBS. You need to write there the path for the following library specified "-l".
I fixed a less obvious situation like this:
Since the problem was hidden in the response file used by JOM I started JOM manually as executed by qmake. Simply copy the JOM call and execute it with an additional -U parameter to see the content of the response file:
C:\Qt\Tools\QtCreator\bin\jom.exe -U -f Makefile.Debug > x.txt
(of course you have to call it in the directory mentioned in the qmake output)
Next I checked all /LIBPATH: occurrences in x.txt. So it was easy to find the culprit and fix the .pro file.

In the current .pro file you specified library names, but didn't specify paths for your external libs. Those '-l' and '-L' keys are used exactly for this.
Some advice:
Use relative paths
Use some variables in .pro file, like DESTDIR and reference them in lib path argument, like -L"$$DESTDIR"

Related

How linux and g++ understand what include path it needs to use?

I'm not quite completely understand how linux or g++ (gcc) define what include path it need to use to find some package. Here is what I mean:
I actually have a c++ project in QtCreator and I use qmake build system. I include in my code a header-only framework file, which needs a Boost of one of the last version. I have already in my system boost-1.64.0, but it's too old, so I've installed boost-1.80.0. But when I try to build the program a compilation error raises with the text:
{name_of_my_pro_file}.pro: rpm boost1.64.0-devel is not installed!!!
I thought if I just replace boost folder in /usr/include/ or /usr/local/include/ with folder of the newer boost version linux can use it instead of older one. But the error mentioned above still raises. I've tried to edit boost folder name in Makefile. Directly in my .pro file there is not any mentions about boost. But nothing helped me. I can handle it only when I renamed boost-1.80.0 folder to boost-1.64.0. And now it works.
It seems that name boost-1.64.0 is written somewhere in the system and it doesn't see any other packages.
I guess that I just don't understand how to work with this stuff correctly and doing something wrong. Can somebody explain what should I do?
My distro is Oracle Linux Server 8.4.
EDIT:
My .pro file:
QT += core gui network xml
QMAKE_CXXFLAGS += -std=c++0x
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TilesDataProvider
TEMPLATE = app
#DESTDIR = ./output
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DEPRECATED_WARNINGS
CONFIG += no_abi_dump
INCLUDEPATH += \
$$PWD \
$$PWD\guts \
$$PWD\SRTM \
$$PWD\tileSources \
/usr/include
CONFIG(release, debug|release){
message(release)
TARGET = TilesDataProvider
OBJECTS_DIR = tmp/TilesDataProvider/release
MOC_DIR = tmp/TilesDataProvider/moc
}
CONFIG(debug, debug|release){
message(debug)
TARGET = TilesDataProvider_d
OBJECTS_DIR = tmp/TilesDataProvider/debug
MOC_DIR = tmp/TilesDataProvider/moc
DEFINES += _DEBUG
}
SOURCES += \
main.cpp \
tileSources/MapTileSource.cpp \
tileSources/SrtmTileSource.cpp \
guts/Position.cpp \
guts/t_task.cpp \
guts/MapConversions.cpp \
SRTM/altdatabank.cpp \
SRTM/altdatamap.cpp \
SRTM/geoid.cpp \
SRTM/srtm_coordinate.cpp \
SRTM/t_geodata.cpp \
SRTM/t_pageid.cpp \
t_image.cpp \
tilesdataprovider.cpp
HEADERS += \
tileSources/MapTileSource.h \
tileSources/SrtmTileSource.h \
guts/MapGraphics_global.h \
guts/Position.h \
guts/t_task.h \
guts/MapConversions.h \
SRTM/altdatabank.h \
SRTM/altdatamap.h \
SRTM/geoid.h \
SRTM/srtm_coordinate.h \
SRTM/t_geodata.h \
SRTM/t_pageid.h \
SRTM/tiff_param.h \
t_image.h \
tilesdataprovider.h

How to remove certain file from a list in .pro file?

When compiling Project 1 a bunch of object files including the main.o are put into buildfolder.
Now I like to use these object files in Project 2 like a library, so what you can do is add all files manually to the the LIBS assignment by
//project2.pro
LIBS += $$buildfolderProject1/compressedair.o \
$$buildfolderProject1/connectca.o \
$$buildfolderProject1/controlpanelca.o \
$$buildfolderProject1/compressedair.o \
$$buildfolderProject1/moc_compressedair.o \
$$buildfolderProject1/moc_controlpanelca.o \
$$buildfolderProject1/moc_screenca.o \
$$buildfolderProject1/qrc_resources.o \
$$buildfolderProject1/screenca.o
A more convenient way would be like this:
//project2.pro
LIBS += $$buildfolderProject1/*.o
But as the buildfolderProject1 also contains the main.o of Project1 you get an error when compiling (multiple definition of main).
So I tried removing main.o by using:
LIBS -= $$buildfolderProject1/main.o
But that does not work with the LIBS += $$buildfolderProject1/*.o method.
There is a way to remove a certain file from list. For explanation:
NOT WORKING:
//project2.pro
LIBS += $$buildfolderProject1/*.o
LIBS -= LIBS -= $$buildfolderProject1/main.o
WORKING:
//project2.pro
myObjectFileList = $$files($$buildfolderProject1/*.o)
myObjectFileList-= $$buildfolderProject1/main.o
LIBS += myObjectFileList
I do not understand totally, but somehow it hast got something to do that $$files returns an editable file list which can be edited in the .pro file.
And in the NOT WORKING Code compiling gets error because qmake extracts all .o files directly without the possibility of editing the list.
In the qmake documentation I found that the qmake built-in $$files function is a replace function.

Qt adding library gstreamer-1.0

I am making a project, dependent on gstreamer-1.0, glib-2.0 and gobject-2.0.
Building in console and in VSCode works fine, but when i get to Qt, i receive the following error message:
:error: cannot find /usr/lib/x86_64-linux-gnu/: File format not recognized
My .pro file:
QT += core
QT -= gui
TARGET = Accord
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
working_directory.cpp \
player_core.cpp \
message.cpp
HEADERS += \
working_directory.h \
message.h \
player_core.h
CONFIG += link_pkgconfig \
c++11
PKGCONFIG += gstreamer-1.0 \
glib-2.0 \
gobject-2.0 \
gio-2.0
INCLUDEPATH += /usr/local/include/ \
/usr/include \
/usr/include/gstreamer-1.0 \
/usr/include/glib-2.0 \
/usr/lib/x86_64-linux-gnu/glib-2.0/include \
/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include
LIBS += /usr/lib/x86_64-linux-gnu/ -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 \
-lgio-2.0 \
With specified pkgconfig should be enough. You don't need to specify the libraries independently. This might be necessary in Windows, but not in Linux. I use the next variables in Linux (Ubuntu):
CONFIG += link_pkgconfig
PKGCONFIG += gstreamer-1.0 glib-2.0 gobject-2.0 gstreamer-app-1.0 gstreamer-pbutils-1.0
If your GStreamer is in the default location it should work.
I solved it by changing QMAKE_CFLAGS_ISYSTEM = -isystem
to QMAKE_CFLAGS_ISYSTEM = -I (can be added to .pro).
for Qt 5.10 +
I think that LIBS += /usr/lib/x86_64-linux-gnu/ is incorrect, hence the
error: cannot find /usr/lib/x86_64-linux-gnu/: File format not recognized.
You probably meant
LIBS += -L/usr/lib/x86_64-linux-gnu/
to add the directory to ld's search path (although that shouldn't be necessary).

Use KDSoap in C++

i try to create a client for a soap service in c++, i try with kdsoap, i build and install easily, but i can't get use in my projects
I create the .pro file with qmake -project, and only add the next line
include ( kiosco-touch.pri )
In their file, i put this content
INCLUDEPATH += \
/home/user/proyects/KDSoap/src \
/home/user/proyects/KDSoap/src/KDSoapClient \
/home/user/proyects/KDSoap/src/KDSoapServer
DEPENDPATH += \
/home/user/proyects/KDSoap/src \
/home/user/proyects/KDSoap/src/KDSoapClient \
/home/user/proyects/KDSoap/KDSoapServer
LIBS += -L/home/user/proyects/KDSoap/lib -l/home/user/proyects/KDSoap/
!isEmpty(QMAKE_LFLAGS_RPATH):LIBS += $$QMAKE_LFLAGS_RPATH/home/user/proyects/KDSoap/lib
include(/home/user/proyects/KDSoap/variables.pri)
DEFINES -= QT_NO_CAST_FROM_ASCII
When i execute qmake and make, i don't get any error of compilation, but says something
"/usr/bin/ld: can not open out file, /bin/kiosco-touch: denied permission”
Redading the Makefile generated, say this
QMAKE_TARGET = kiosco-touch
DESTDIR = /bin/#avoid trailing-slash linebreak
TARGET = /bin/kiosco-touch
For one reason, try create executable file with bin.
So i will edit the .pro or .pri files for read and create correctly the executable, someone have example with this library, or knows how i will read the libraries.
Well, i update the post, finally i can get with work, change the .pri file and now content this.
LIBS += -L/home/user/proyects/KDSoap/lib -lkdsoap
INCLUDEPATH += \
/home/user/proyects/KDSoap/include \
/home/user/proyects/KDSoap/src \
/home/user/proyects/KDSoap/src/KDSoapClient \
/home/user/proyects/KDSoap/src/KDSoapServer
DEPENDPATH += \
/home/user/proyects/KDSoap/src \
/home/user/proyects/KDSoap/include \
/home/user/proyects/KDSoap/src/KDSoapClient \
/home/user/proyects/KDSoap/src/KDSoapServer
And too is necessary create enviroment variable $LD_LIBRARY_PATH as is described by the installation manual.

Sha512 hash in QT via OpenSSL

I'm trying to use the Sha512 function in openSSL but can't seem to get it to work as I get compiler errors just starting into the code. I include #include <openssl/sha.h> at the top of the .cpp file, then in the action of a button event I put just the following code below.
SHA512_CTX ctx;
SHA512_Init(&ctx);
//Will uncomment below in later if I get SHA512_Init to work
//SHA512_Update(&ctx, string, strlen(string));
//SHA512_Final(digest, &ctx);
I get a linker error telling my undefined symbols for architecture x86_64, implying the function does not exist?
I'm aware QT 5 has a hash function, but I'm limited to QT 4.8 so I can not use the cryptographic sha512 hash function available in the QT 5+ framework.
Any help is appreciated!
Used macports to install openssl
I'm using Mac OS 10.9.2
MAKE FILE
#-------------------------------------------------
#
# Project created by QtCreator 2014-06-11T20:27:49
#
#-------------------------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ExchangeTab
TEMPLATE = app
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
SOURCES += main.cpp\
mainwindow.cpp \
httpsocket.cpp \
cloaksend.cpp \
exchange.cpp
HEADERS += mainwindow.h \
httpsocket.h \
cloaksend.h \
exchange.h
FORMS += mainwindow.ui
RESOURCES += \
AppResources.qrc
Looking for cross platform solution please.
You need to link to the right library (openSSL)
Have a look here: How to Include OpenSSL in a Qt project
Specifically, add this to your .pro file.:
LIBS += -L/opt/local/lib/ -lcrypto
For including .h files add this line to your .pro file :
INCLUDEPATH += /opt/local/include
[1] says that the default include path will be /opt/local/include/.
LIBS += -L/usr/include/openssl -openssl
INCLUDEPATH += /usr/include/openssl
This looks incorrect. The OpenSSL libraries are libcrypto (-lcrypto) and libssl (-lssl). There is nolibopenssl(-lopenssl). Try:
LIBS += -L/usr/lib -lcrypto
INCLUDEPATH += /usr/include/openssl
But the libraries are version 0.9.8. You might consider upgrading to 1.0.1h.
$ ls /usr/lib | grep crypto
libcrypto.0.9.7.dylib
libcrypto.0.9.8.dylib
libcrypto.dylib
libk5crypto.dylib
And
$ /usr/bin/openssl version
OpenSSL 0.9.8y 5 Feb 2013
If you choose to upgrade, OpenSSL will install into /usr/local/ssl. Avoid mixing/matching version of OpenSSL with the following.
INCLUDEPATH += /usr/local/ssl/include/openssl
LIBS += /usr/local/ssl/lib/libcrypto.a
Its OK to specify objects and archives in LIBS. See How to add object files to a project in Qt.
Okay so I may have answered my own question but I will need some help understanding why it worked.
My make file was indeed the problem. I added the following 3 lines.
INCLUDEPATH += $$OPENSSL_INCLUDE_PATH
LIBS += $$join(OPENSSL_LIB_PATH,,-L,)
LIBS += -lcrypto
Then it magically compiled just fine. I found these in another project made with QT that compiled for OpenSSL.
Interestingly enough. I removed the top two lines so only the following remained. Then ran the clean on my project to be sure the code was being recompiled.
LIBS += -lcrypto
This also just 'worked' without linker errors. It looks like that is the only command I need. Question is... will that be cross platform friendly if I take this code and compile on linux or windows? That I am not sure, but this worked.