Undefined refence to "main"
-
When I do so i.e replacing TEMPLATE = app by TEMPLATE = lib in the src.pro file , it leads to other errors.
In an other computer it work with TEMPLATE = app without this "undefined reference to main" issue so I'm looking for an explanation about how QT creator build the project in the other computer.
-
@Christian-Ehrlicher when I define src as a library I get
/usr/bin/ld: cannot find -lmyapp
Makefile:127: recipe for target 'app' failed
make[1]: Leaving directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/app'
Makefile:68: recipe for target 'sub-app-make_first' failed
collect2: error: ld returned 1 exit status
make[1]: *** [app] Error 1
make: *** [sub-app-make_first] Error 2
15:01:17: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project anchorage (kit: QT5)
When executing step "Make" -
As already pointed out earlier, your project, as it is can not compile.
As for your LIBS statement, the library is generated in the shadow build folder, not in your sources where you are pointing it to. Use the OUT_PWD variable as starting folder.
-
Hello SGaist and merry Christmas,
Thanks again for your help but once again I can't figure out what you want me to do exactly. So here is how I understood your advice :
- As you told me in one of your first post I need to set "TEMPLATE = lib" instead of "TEMPLATE = app" in my src.pro file
- Now when I compile the compiler doesn't find -lmyapp (by the way I don't know if "myapp" is a generic name ) because in my app.pro file I point to ../src in line "LIBS += -L../src -lmyapp"
- Instead of ../src I tried $OUT_PWD or $OUT_PWD/src but the compiler still doesn't find -lmyapp :(
I guess I didn't understand your post
-
@R-griset said in Undefined refence to "main":
As you told me in one of your first post I need to set "TEMPLATE = lib" instead of "TEMPLATE = app" in my src.pro file
If you want to build a library, use the former one, if you want to build a program, use "app".
Now when I compile the compiler doesn't find -lmyapp (by the way I don't know if "myapp" is a generic name )
You tell the linker to link against a library
libmyapp.so
, and-L
specifies the path to this library. So check if you have such a library (and where!), and if it already exists at the time the linker is invoked.By the way:
/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/app'
I strongly advice against project paths containing spaces or other special characters! Already this small piece might lead to build, debug or deploy errors.
Regards
-
Hello aha_1980 and thanks for your advices,
No I don't have "libmyapp.so" anywhere because it should be compile from src folder and call by the application from app folder. At the beggining in the code it was written "app" but it doesn't compile because it is looking for a main function which doesn't exist in src.
Thanks for the advice about the folder name, once again it s not my project but I changed the name ;)
-
That's the main issue here: the project as written by default can't compile because what you have in the arc folder should be built as a library and that library linked to your application.
If anything, I would recommend starting by cleaning up the project structure so you have something clear to use.
-
Ok lets try :),
I compiled src as lib appart and i'm having a libsrc.so in a build-src-QT5-Debug folder
Now, I removed src folder from the MainPro.pro and I added the line
LIBS += -L../build-src-QT5-Debug/ -lsrc in my app.pro file
And i'm still getting an error :
14:32:57: Starting: "/usr/bin/make"
cd app/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake /home/d07876/Desktop/Ancrage/UIAncrage/UI_11_05_test1Folder/app/app.pro -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && /usr/bin/make -f Makefile
make[1]: Entering directory '/home/d07876/Desktop/Ancrage/UIAncrage/build-anchorage-QT5-testLibAppart/app'
/usr/lib/x86_64-linux-gnu/qt5/bin/qmake -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug -o Makefile ../../UI_11_05_test1Folder/app/app.pro
g++ -Wl,-rpath,'$ORIGIN/../src',--enable-new-dtags -o app main.o -L/usr/X11R6/lib64 -L../build-src-QT5-Debug/ -lsrc -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
/usr/bin/ld: cannot find -lsrc -
As already suggested use OUT_PWD to have a full path to the folder where the library can be found.
-
How are you building it ?
-
Maybe we are missunderstanding from the very beginning, src.pro is not a library but only the sources of the project, in app folder you have nothing except a main function directly calling function from src folder. I think my predecessor who wrote the code just separate it to be clearer and that's why the TEMPLATE was app because it is an app whose source files are in src folder.
I'm building it by opening directly the src.pro as a project and building it as a library before trying to build the app