team-phoenix / Phoenix

A multi-system emulator and library manager designed to be both powerful and easy to use.
http://phoenix.vg
GNU General Public License v2.0
376 stars 40 forks source link

undefined reference to `qInitResources_backend_input_controllerdb #313

Closed mdeguzis closed 7 years ago

mdeguzis commented 8 years ago

Having trouble linking the final exe when running the project into cmake. I'm looking through CMakeCache.txt now. I see where the code is for this, just a bit unsure. I see in CMakeLists.txt, that my Qt paths and programs are picked up.

[ 98%] Building CXX object CMakeFiles/Phoenix.dir/CMakeFiles/Phoenix.dir/qrc_controllerdb.cpp.o
[100%] Linking CXX executable Phoenix
CMakeFiles/Phoenix.dir/frontend/cpp/main.cpp.o: In function `main':
/build/phoenix-0.0.1+20160823git+bsos/frontend/cpp/main.cpp:86: undefined reference to `qInitResources_backend_input_controllerdb()'
collect2: error: ld returned 1 exit status
CMakeFiles/Phoenix.dir/build.make:1382: recipe for target 'Phoenix' failed
make[4]: *** [Phoenix] Error 1
make[4]: Leaving directory '/build/phoenix-0.0.1+20160823git+bsos/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Phoenix.dir/all' failed
make[3]: *** [CMakeFiles/Phoenix.dir/all] Error 2
make[3]: Leaving directory '/build/phoenix-0.0.1+20160823git+bsos/build'
Makefile:83: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/build/phoenix-0.0.1+20160823git+bsos/build'
debian/rules:7: recipe for target 'override_dh_auto_build' failed
make[1]: *** [override_dh_auto_build] Error 2
make[1]: Leaving directory '/build/phoenix-0.0.1+20160823git+bsos'
debian/rules:4: recipe for target 'build' failed
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2

Could I be missing a package? I've backported much of the Qt stack to Debian Jessie / SteamOS. Maybe something is being missed on the backend, or I have some silly error :/ From what I read, linking is either incomplete in CMakeLists.txt somewhere, or implemented in a different manner.

athairus commented 8 years ago

That function is generated by rcc. The file Phoenix/backend/input/SDL_GameControllerDB/gamecontrollerdb.txtis referred to by Phoenix/backend/input/SDL_GameControllerDB/controllerdb.qrc. CMake should invoke rcc but it either didn't this time or it's not being passed to the linker. What version of CMake are you using? You'll need at least 3.6.0.

Check build_folder/Phoenix_automoc.dir/backend/input/qrc_controllerdb.cpp. You should see the missing function defined towards the bottom.

mdeguzis commented 8 years ago

I am using CMake 3.6.1. Ok, i'll review that now. Thank you for the response.

mdeguzis commented 8 years ago

I have qrc_controllerdb.cpp in /build/CMakeFiles/Phoenix.dir/. Here is the contents of that file.

athairus commented 8 years ago

On my box I have qInitResources_backend_input_controllerdb() within qrc_controllerdb.cpp. Try building outside the source tree? Yours seems to be missing the path part in the function name, which is causing some sort of mismatch?

mdeguzis commented 8 years ago

My build process is outlined here for debian/rules. I always try to use a build folder to contain the files. How can I build outside the src tree? cd up a level and try building? Maybe because I have CMakeFiles before Phoenix.dir :/ no idea. Maybe my use of "build" is being picked up as a var elsewhere. I'll change the folder name.

athairus commented 8 years ago

Yes. Something like this:

mkdir Phoenix && cd Phoenix
git clone phoenix[...]
mkdir phoenix-build && cd phoenix-build
cmake ../phoenix [...]
[etc]
mdeguzis commented 8 years ago

Hmm.... no luck with:

    rm -rf phoenix_build  && mkdir phoenix_build
    cd phoenix_build && cmake \
        -DCMAKE_BUILD_TYPE=Debug \
        -DCMAKE_EXPORT_COMPILE_COMMANDS=on \
        -DCMAKE_INSTALL_PREFIX=/usr ..
    make -C phoenix_build

I even tried doing this manually:

rm -rf phoenix_build  && mkdir phoenix_build
cd phoenix_build
cmake ..
make
athairus commented 8 years ago

You're not putting phoenix_build inside the source tree are you? Is phoenix_build in the same folder as backend, CMake, externals and frontend is it?

mdeguzis commented 8 years ago

Yes, phoenix build is inside the build directory with the source files. Every project I have every build with cmake employs similar processes:

rm -rf  Build  && mkdir Build  
cd Build  && cmake ..
make -C Build

Not sure how I will tackle this then if it must be outside of the source files entirely. That's why I thought build directories existed in the first place, to ensure build files are contained and clean, not outside of the source directory entirely.

athairus commented 8 years ago

Out of tree builds are how Qt Creator does it, it allows for multiple build configurations to coexist without overwriting each other. Please try doing it out of tree, simply point CMake in line 2 to the source folder.

mdeguzis commented 8 years ago

Did these exact steps from the $HOME directory of my Debian 8 VPS:

mkdir Phoenix && cd Phoenix
git clone https://github.com/team-phoenix/Phoenix
mkdir phoenix-build && cd phoenix-build
cmake ../Phoenix
make

No luck :/ It appears your Travis CI build doesn't build out of tree. Maybe that is what the env source is for above it.

athairus commented 8 years ago

What version of Qt are you using?

mdeguzis commented 8 years ago

5.7.0 CmakeCache finds all required packages.

If there is a way to spit out more verbose cmake output, I will give you logs.

mdeguzis commented 8 years ago

I turned on some debugging with cmake and make: http://sprunge.us/UYYQ

Doesn't this mean the naming is being generated incorrectly here? It would appear the default behavior of rcc is to match the name of the input file, in this case "controllerdb" vs "backend_input_controllerdb".

Generating qrc source CMakeFiles/Phoenix.dir/qrc_controllerdb.cpp
/usr/lib/x86_64-linux-gnu/qt5/bin/rcc -name controllerdb -o /build/phoenix_build/CMakeFiles/Phoenix.dir/qrc_controllerdb.cpp /build/phoenix-0.0.1+20160823git+bsos/backend/input/controllerdb.qrc

You said above:

That function is generated by rcc. The file Phoenix/backend/input/SDL_GameControllerDB/gamecontrollerdb.txtis referred to by Phoenix/backend/input/SDL_GameControllerDB/controllerdb.qrc.

But that file is not in a "SDL_GameControllerDB" subdir. I see it's an alias, but just wanted to be sure.

../Phoenix/backend/input/controllerdb.qrc

Update:

renaming the file and the file name in input/backend/CMakeLists.txt works. So I don't know how you are changing the generation of the name. This works fine with a temp build dir inside or outside the source tree. If the path is globbed and used as filename input, where is this done in code? Why do this vs just setting the path into the filename/CMakeLists?

athairus commented 8 years ago

I can confirm the problem is due to some regression/new bug caused by CMake 3.6.1. Try 3.6.0. I'll look into it more and see whose fault it is, mine or theirs.

mdeguzis commented 8 years ago

Will do. Thank you for checking. If it's a cake problem, fine to use I'd think.

bsmt commented 7 years ago

So looking at the generated qrc_controllerdb.cpp file, it puts the function we want as qInitResources_controllerdb() instead of qInitResources_backend_input_controllerdb(). Since the offending macro at line 86 of main.cpp is Q_INIT_RESOURCE( backend_input_controllerdb ), I figure you can just change it to Q_INIT_RESOURCE( controllerdb ). I did this and now it compiles. No idea if it broke anything at runtime, because there are other bugs preventing me from testing. I can submit a PR if you'd like.

bsmt commented 7 years ago

Can probably close this now.

athairus commented 7 years ago

I remember doing your fix @bsmt a while ago and it didn't work. Seems to work with the latest CMake (as of this posting 3.7.2) so I'll keep that commit and close this.

bsmt commented 7 years ago

Well it's not going to build with cmake < 3.7 now it seems, which is why the travis build failed. I guess building will just require a new cmake, which is okay imo.