2

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135
Federico
  • 321
  • 1
  • 2
  • 11
  • Have you tried absolute path to -l, e.g. -lqscintilla/Qt4Qt5/libqscintilla2.a? Show the whole linker output please what it is trying to execute. – László Papp Feb 24 '14 at 02:46
  • Are you also trying to build the qscintilla library as part of your project, or just include it as a static library? I would see no any reason to do the latter. – László Papp Feb 24 '14 at 07:48
  • @LaszloPapp that didn't work, unfortunately. What I find strange is that running `make` via terminal works perfectly, using the same `.pro` file and everything. – Federico Feb 24 '14 at 18:19
  • Are you using the same build folders in both the terminal and the console? Perhaps you could try "OUT_PWD" as per the explanation below? – László Papp Feb 24 '14 at 18:33

3 Answers3

1

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135
  • Yes, this is a better solution. For some reason using `OUT_PWD` didn't work, but `_PRO_FILE_PWD_` did (with shadow build enabled). Edit: I tried printing the variables using qmake's `message()` function, and it appears that `PWD` and `_PRO_FILE_PWD_` point to the project's original root directory, while `OUT_PWD` points to the one generated by Qt. – Federico Feb 24 '14 at 18:44
0

You should also add the line:

PRE_TARGETDEPS += qscintilla/Qt4Qt5/libqscintilla2.a

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

Nejat
  • 31,784
  • 12
  • 106
  • 138
  • @LaszloPapp What would be a better option? Right now, I can just download the latest version of QScintilla, save it in my project dir, compile it and link it statically. I find it very practical, as I can replace the files easily if the author releases a new version. – Federico Feb 24 '14 at 18:17
0

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.

Federico
  • 321
  • 1
  • 2
  • 11
  • This seems to be a workaround, but it will disable the shadow builds as well. Anyway, I still gave a +1 for the question. :-) – László Papp Feb 24 '14 at 18:28