Question

I'm having a problem while using QtCreator 3.0.1 with Qt 5.2.1 on Linux. I'm trying to compile my project using QtCreator's built in 'build' function, which I imagine runs qmake project.pro and then make. My project uses QScintilla, which I have compiled into a static library (.a), and included in my project's directory in qscintilla/Qt4Qt5.

After compilation is done, the compile output pane shows the following:

/usr/bin/ld: cannot find -lqscintilla2
collect2: error: ld returned 1 exit status

My .pro file contains:

LIBS += -Lqscintilla/Qt4Qt5 -lqscintilla2

However, running qmake and then make on the project's root directory via a terminal emulator works perfectly, and the project is compiled and linked successfully. I have double checked that the qscintilla/Qt4Qt5 directory contains the file libqscintilla2.a.

Was it helpful?

Solution

Since you seem to be using Linux, it would be better to leave the package with your distribution. Getting packages installed bringing static libraries into the system would be more "vanilla".

However, if you wish to stick to the in-project build principle, I would suggest not to disable the shadow build and create other workarounds having their own limitations.

You could for instance use the $$OUT_PWD variable for this purpose, but in general, you would need to specify the target dependency as well between the components.

So, you would be writing something like this then:

LIBS += -L$$OUT_PWD/qscintilla/Qt4Qt5 -lqscintilla2

Please adjust this based on your directory layout.

OTHER TIPS

You should also add the line:

PRE_TARGETDEPS += qscintilla/Qt4Qt5/libqscintilla2.a

to your .pro file in order to link the library statically.

Managed to make it work: on QtCreator, click on "Projects" on the left pane, which will open a tab which allows you to edit the build/run/style options. On the Build/General section, disable "Shadow build". This will build the project on the original project directory.

Edit: see @LaszloPapp's answer for a better solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top