Qt linker errors: cannot find -lQtCored
You only need the following content:
TARGET = ProgName
TEMPLATE = app
CONFIG += console
QT -= gui
SOURCES += ...
HEADERS += ...
That is because core
and gui
are added to the QT
variable automatically. In this particular case however, you can remove the gui
default if you wish to build a console application as you seem. Although "CONFIG += console" could eventually do that for you. Besides this, everything will work automatically for you, so you do not need to pass the library path to the qt libraries and so forth. You would only need to use QT += widgets
and similar lines if you used further Qt modules there are not there by default. Even then, you would not need to set the Qt library path as you did in your question.
Besides, if you wanna target cross-platform later, you may wish to add this:
CONFIG -= app_bundle
to avoid creating Mac bundle for console based applications.
If you have multiple versions of Qt installed as it seems, you need to use the qmake from the required version, and it will be fine. Just to give an example: I use qmake
for Qt 5 on my Archlinux system, and qmake-qt4
for Qt4.
On windows, you should either have the desired qt installation bin in the path before the undesired, or you need to call desired qmake explicitly, something like C:\path\to\my\desired\qmake
.
QT Creator Linker Error: Link2019 File Not Found
By making the function static
you gave it internal linkage. This means the definition of your function will only be found in the translation unit in which it is defined (i.e, terrain.cpp
) and not main.cpp
. Remove the static keyword.
This is very easy to confirm with objdump
. Say you have test.h
:
#ifndef _TEST_H
#define _TEST_H
static void a_func();
#endif
test.cpp
:
#include "test.h"
void a_func()
{
}
main.cpp
:
#include "test.h"
void a_func()
{
}
int main()
{
}
You'll notice that you won't get a function redefinition error. We can compile each file separately to inspect the objects:
g++ -c test.cpp -o test.o
g++ -c main.cpp -o main.o
Both will show a_func
:
Disassembly of section .text:
0000000000000000 <_ZL6a_funcv>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 90 nop
5: 5d pop %rbp
6: c3 retq
Now what about the final binary?
g++ main.o test.o
objdump -d ./a.out
00000000004005b6 <_ZL6a_funcv>:
4005b6: 55 push %rbp
4005b7: 48 89 e5 mov %rsp,%rbp
4005ba: 90 nop
4005bb: 5d pop %rbp
4005bc: c3 retq
00000000004005bd <main>:
4005bd: 55 push %rbp
4005be: 48 89 e5 mov %rsp,%rbp
4005c1: b8 00 00 00 00 mov $0x0,%eax
4005c6: 5d pop %rbp
4005c7: c3 retq
00000000004005c8 <_ZL6a_funcv>:
4005c8: 55 push %rbp
4005c9: 48 89 e5 mov %rsp,%rbp
4005cc: 90 nop
4005cd: 5d pop %rbp
4005ce: c3 retq
4005cf: 90 nop
It appears twice! This is why you don't make functions static in a header file meant to be shared across multiple translation units.
C++ Qt framework: qmake exits with error code 2, can not find project.pro file, yet it's there
Are you sure that you don't have space or other 'weird' characters in your project's path? If so, Qt is unhappy.
You may also try to delete the *.pro.user
file and try to compile again.
If unfortunately neither of them work, you can try to compile your project on the command line.
cd
to the root directory of your project and:
qmake -project
mingw32-make
If this still can't get your project compiled, you should check your Qt installation.
Qt Creator 2.1.0 can't find Qt, looks in wrong place
http://bugreports.qt-project.org/browse/QTBUG-18230
Turns out .qmake.cache was out of date, deleting it solved the problem.
Qt can't find files in a subproject
JenkinsTestMain/ is not in the INCLUDEPATH, thus person.h is not found.
In JenkinsTestSuite.pro, you must add
INCLUDEPATH += ../JenkinsTestMain
Alternatively, use #include in the test.
I also suggest to add a DEPENDPATH += for each INCLUDEPATH +=, otherwise changes to person.h won't trigger persontest.cpp to be recompiled, which leads to wrong behaviour and crashes.
Another issue here is that person.cpp is not part of JenkinsTest. You must either compile person.cpp another time for JenkinsTest, or put that code into a shared library.
Related Topics
Best Compiler Warning Level For C/C++ Compilers
Default Value of Function Parameter
How to Redirect Qdebug, Qwarning, Qcritical etc Output
How to Measure Cpu Time and Wall Clock Time on Both Linux/Windows
Why Can't Clang With Libc++ in C++0X Mode Link This Boost::Program_Options Example
How to Catch Segmentation Fault in Linux
When to Overload the Comma Operator
Const& , & and && Specifiers For Member Functions in C++
Converting a Pointer into an Integer
Why Are String Literals L-Value While All Other Literals Are R-Value
Does C++ Call Destructors For Global and Class Static Variables
Convert an Int to Ascii Character
Why Can Lambdas Be Better Optimized by the Compiler Than Plain Functions
String Literal Matches Bool Overload Instead of Std::String
C++ Detect When User Presses Arrow Key
How to Specify How Many Characters of a String to Print Out Using Printf()