linker error: can't find _main [message #644175] |
Thu, 09 December 2010 13:30  |
Eclipse User |
|
|
|
Hi, all
I'm not sure this is an eclipse problem per se, but in my current project (a very simple Qt integration), I'm getting the following error:
Quote: | _main in hello.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [hello] Error 1
|
I've created several other projects that built without incident. The only differences I can see about this one is:
- I'm including some Qt files
- main is getting passed argv and argc
In fact, here's the entirety of the code:
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton hello("Hello world!");
hello.resize(100, 30);
hello.show();
return app.exec();
}
Thanks for any help.
|
|
|
|
|
Re: linker error: can't find _main [message #647847 is a reply to message #647829] |
Sun, 09 January 2011 21:28   |
Eclipse User |
|
|
|
Thanks for responding. Here's the output from the console:
**** Build of configuration Debug for project hello ****
make all
Building file: ../src/hello.cpp
Invoking: GCC C++ Compiler
g++ -I/Library/Frameworks/QtGui.framework/Versions/4/Headers -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/hello.d" -MT"src/hello.d" -o"src/hello.o" "../src/hello.cpp"
Finished building: ../src/hello.cpp
Building target: hello
Invoking: MacOS X C++ Linker
g++ -o "hello" ./src/hello.o
Undefined symbols:
"QString::free(QString::Data*)", referenced from:
QString::~QString()in hello.o
"QPushButton::QPushButton(QString const&, QWidget*)", referenced from:
_main in hello.o
"QWidget::resize(QSize const&)", referenced from:
QWidget::resize(int, int)in hello.o
"QString::fromAscii_helper(char const*, int)", referenced from:
QString::QString(char const*)in hello.o
"QPushButton::~QPushButton()", referenced from:
_main in hello.o
_main in hello.o
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in hello.o
"QApplication::exec()", referenced from:
_main in hello.o
"QApplication::~QApplication()", referenced from:
_main in hello.o
_main in hello.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [hello] Error 1
|
|
|
|
|
Re: linker error: can't find _main [message #648001 is a reply to message #647981] |
Mon, 10 January 2011 12:49   |
Eclipse User |
|
|
|
I noticed in the command that Qt was not being linked, which is done with -framework Foo (Mac only) or -lfoo or libfoo.a. Hence the undefined symbols. I don't know how familiar you are with linking vs compiling... If you get undefined symbols for external libraries, it usually means that you are not linking the libraries. On Mac this is often done with the -framework flag.
By default, the linker will look for frameworks in those two directories:
/Library/Frameworks
/System/Library/Frameworks
For examble, I saw QString::free was not defined so I looked for it and found a header:
/Library/Frameworks/QtCore.framework/Headers/QString
which means QtCore probably needs to be linked! So I added -framework QtCore
I have an extra tip for you using CDT on Mac with frameworks. Currently, CDT doesn't play well frameworks so you don't get nice code completion and navigation for code in frameworks.
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=69529
BUT, you can workaround that by creating symbolic links which will make QtCore.framework/Headers/QString look like QtCore/QString to CDT
Here's what I do
cd /Users/mark/Documents/dev/cpp/include
ln -s /Library/Frameworks/QtCore.framework/Headers QtCore
ln -s /Library/Frameworks/QtGui.framework/Headers QtGui
etc...
Then in Eclipse, in my project properties, C/C++ General, Paths and symbols, in the Includes tab, Add..., File system..., I browse for /Users/mark/Documents/dev/cpp/include, Ok. BUT sometimes Qt stuff gets included without the framwork path, like #include<QPushButton> instead of #include <QtGui/QPushButton> so I add those includes paths as well:
/Users/mark/Documents/dev/cpp/include/QtGui
/Users/mark/Documents/dev/cpp/include/QtCore
So for your small project, I ended up with 3 include paths
/Users/mark/Documents/dev/cpp/include
/Users/mark/Documents/dev/cpp/include/QtGui
/Users/mark/Documents/dev/cpp/include/QtCore
and my build command looked like this:
g++ -I/Users/mark/Documents/dev/cpp/include -I/Users/mark/Documents/dev/cpp/include/QtCore -I/Users/mark/Documents/dev/cpp/include/QtGui -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testQt.d" -MT"src/testQt.d" -o "src/testQt.o" "../src/testQt.cpp
then
g++ -framework QtCore -framework QtGui -o "testQt" ./src/testQt.o
And if I type hello.[ctrl+space] I get all the sweet completion proposals!
Hope this helps!
[Updated on: Mon, 10 January 2011 16:12] by Moderator
|
|
|
|
Re: linker error: can't find _main [message #690688 is a reply to message #648001] |
Wed, 29 June 2011 22:40  |
Eclipse User |
|
|
|
Marc-Andre,
I included a few frameworks includes as you suggested, and two things happened.
1) the compilation time increased by a factor of magnitude.
2) the included frameworks require other frameworks, which produce a lot of errors.
How do you cope with these issues?
Thanks.
--8
|
|
|
Powered by
FUDForum. Page generated in 0.05847 seconds