tags:

views:

634

answers:

5

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.

(To make matters worse, I do not have access to a Linux machine myself quite yet and so I have very limited info about this error. I will post more info when I get more, of course.)

A: 

Usually there are 3 areas where this breaks:

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

good luck!

Karol Wilk
A: 

Make 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 distros 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
Derick
A: 

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.

Rohan Prabhu
+1  A: 

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.

qid
A: 

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

KIM