Solved Add source files - works on CLI, not in Qt Creator
-
I am trying to compile with three C source files. I cannot figure out where in Qt Creator to put this declaration. When I add the three files when compiling on the command line, it works just fine.
Here is the command Qt uses:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -stdlib=libc++ -headerpad_max_install_names -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.10 -Wl,-rpath,@executable_path/Frameworks -Wl,-rpath,/Users/jonathancunningham/Qt5.9.0/5.9/clang_64/lib -o RansomSnare.app/Contents/MacOS/RansomSnare ent.o randtest.o main.o mainwindow.o moc_mainwindow.o -F/Users/jonathancunningham/Qt5.9.0/5.9/clang_64/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL
That command gives me an error stating 'Undefined symbols'.
When using the CLI, I add the files to the end of the statement:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -stdlib=libc++ -headerpad_max_install_names -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.10 -Wl,-rpath,@executable_path/Frameworks -Wl,-rpath,/Users/jonathancunningham/Qt5.9.0/5.9/clang_64/lib -o RansomSnare.app/Contents/MacOS/RansomSnare ent.o randtest.o main.o mainwindow.o moc_mainwindow.o -F/Users/jonathancunningham/Qt5.9.0/5.9/clang_64/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL ../fslogger/fslogger/entropy/ent.c ../fslogger/fslogger/entropy/randtest.c ../fslogger/fslogger/entropy/iso8859.c
And the program compiles just fine!
Any help is greatly appreciated!
-
Is there more to the error than just 'Undefined symbols'? Did you intentionally leave off the c source files in the Qt version of the command or were they really missing? Can you share your project file (.pro)?
-
@mchinand said in Add source files - works on CLI, not in Qt Creator:
ave off the c source files in the Qt version of the comma
Thanks for replying, mchinand! I did not intentionally leave off the c source files in the Qt version. I do not know how to add them in Qt Creator so that they will show up in the Compile Output.
The full Undefined Symbols message is:Undefined symbols for architecture x86_64: "CalculateEntropy(char*, unsigned long, double*, double*, double*, double*, double*)", referenced from: _main in main.o "_isoalpha", referenced from: _CalculateEntropy in ent.o "_isoupper", referenced from: _CalculateEntropy in ent.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [RansomSnare.app/Contents/MacOS/RansomSnare] Error 1 13:02:08: The process "/usr/bin/make" exited with code 2. Error while building/deploying project RansomSnare (kit: Desktop Qt 5.9.0 clang 64bit) The kit Desktop Qt 5.9.0 clang 64bit has configuration issues which might be the root cause for this problem. When executing step "Make"
The .pro file:
#------------------------------------------------- # # Project created by QtCreator 2017-06-30T09:21:40 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = RansomSnare TEMPLATE = app # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += ent.c randtest.c main.cpp mainwindow.cpp HEADERS += \ mainwindow.h FORMS += \ mainwindow.ui
-
Are all the source files in the same directory as your project file and are you building in a different directory from your source directory ('shadow build' in Creator's project settings and the recommended configuration). In your working case, you aren't compiling main.cpp or mainwindow.cpp; how were these compiled? It seems like ent.c and randtest.c are in another directory according to your use of a relative path in your working compile command.
-
I moved the source files into the same directory for troubleshooting. Ideally, the files would not need to be in the same directory. As far as compilation, I'm simply going to Qt Creator and choosing "Build All".
-
@jbc22 said in Add source files - works on CLI, not in Qt Creator:
I moved the source files into the same directory for troubleshooting. Ideally, the files would not need to be in the same directory. As far as compilation, I'm simply going to Qt Creator and choosing "Build All".
RIght, I wasn't suggesting you move the files, but instead change SOURCE line in your project file to include the path (or relative path) for the source files that are in a different directory from the project file.
-
If I do that, I receive the same message. For example, I changed the SOURCE line in the .pro file to:
SOURCES += ../another/project/entropy/ent.c ../another/project/entropy/randtest.c main.cpp mainwindow.cpp
And the error remains:
Undefined symbols for architecture x86_64: "CalculateEntropy(char*, unsigned long, double*, double*, double*, double*, double*)", referenced from: _main in main.o "_isoalpha", referenced from: _CalculateEntropy in ent.o "_isoupper", referenced from: _CalculateEntropy in ent.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [RansomSnare.app/Contents/MacOS/RansomSnare] Error 1 19:06:17: The process "/usr/bin/make" exited with code 2. Error while building/deploying project RansomSnare (kit: Desktop Qt 5.9.0 clang 64bit) The kit Desktop Qt 5.9.0 clang 64bit has configuration issues which might be the root cause for this problem. When executing step "Make"
-
I was missing another source file in the .pro file. Now I'm closer to compilation. There's another undefined symbol. I've looked at all headers and source files. They are included in the .pro file. Here's the output:
Undefined symbols for architecture x86_64: "CalculateEntropy(char*, unsigned long, double*, double*, double*, double*, double*)", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [RansomSnare.app/Contents/MacOS/RansomSnare] Error 1 11:30:44: The process "/usr/bin/make" exited with code 2. Error while building/deploying project RansomSnare (kit: Desktop Qt 5.9.0 clang 64bit) The kit Desktop Qt 5.9.0 clang 64bit has configuration issues which might be the root cause for this problem. When executing step "Make"
-
We found the issue. With the header file, we needed to do an:
extern "C" {
#include "file.h"
}