Nate
Nate

Reputation:

Qt cross-platform issue: compiles fine on Windows, linker error on Linux

I have some Qt code called "GUI". Via Qt Creator, I am able to compile (using GCC) it without any complaints on Windows. However, when I try to compile it (again using GCC via Qt Creator) on Linux, I get a linker error:

collect2: ld returned 1 exit status.

The only non-Qt library that I use is the STL's vector library.

Upvotes: 1

Views: 1103

Answers (5)

Derick Schoonbee
Derick Schoonbee

Reputation: 3021

Make sure your Qt environment is setup and that you have all the library/package dependencies.

Then run qmake and then make. If qmake runs you should be fine.

On some Linux distributions you need to specifically install the libraries (packages). Some packages will allow you to run the program, for example MySQL plugins. If you want to compile you would need the development packages too.

For example, in Ubuntu you might need to run:

sudo apt-get install build-essential
sudo apt-get install libqt4-sql-mysql

Upvotes: 0

bgs
bgs

Reputation: 1250

Usually there are three areas where this breaks:

  • Check your Qt project file, and see if you need to add LIBS += library/path/etc
  • You don't have the library installed
  • If it is installed, modify your LD_LIBRARY_PATH=/missing/lib/path:$LD_LIBRARY_PATH ./binary on the fly

Upvotes: 0

KIM
KIM

Reputation: 1254

Deleting .moc / .obj you can try it again.

Upvotes: 0

qid
qid

Reputation: 1913

The given error message simply means that when it attempted to link all of your object files together into an executable, something went wrong; if you switch to the Compile Output tab in Qt Creator, you should be able to track down the actual error message from the linker itself. It could be as simple as not being able to write to the location where the executable is supposed to go (I've had that happen when I try to rebuild an application I still have running), or it could be something more serious. If you've started adding a class that doesn't have its methods implemented yet, for example.

Upvotes: 1

Rohan Prabhu
Rohan Prabhu

Reputation: 7302

The error: "collect2: ld returned 1 exit status" is generally returned when the moc is not run on files it is supposed to run on [specifically, any files that define a Q_OBJECT]. Check if your moc is running properly.

Also, in Qt Creator, there is a 'Build info' tab. Go over it and check for more information about this error.

Upvotes: 0

Related Questions