alariq / mc2

Mech Commander 2 open source engine + OpenGL Linux port
https://alariq.github.io/mc2-website
GNU General Public License v3.0
122 stars 19 forks source link

Linux compilation needs some adjustments: includes for size_t, ptrdiff_t and function pointer passing #11

Closed burger-drip closed 3 years ago

burger-drip commented 3 years ago

Nice project.

cmake does most of the work for the build, but a little tweaking is needed to get it closer to a build.

First is due to lack of includes

vfx_ellipse.cpp:19:3: error: ‘size_t’ was not declared in this scope
vfxtile.cpp:685:63: error: ‘ptrdiff_t’ has not been declared

maybe throw in a #include <stddef.h> in vfxtile.cpp

Other compiler errors. I don't really know about why these callbacks were set to color. It doesn't seem to play nice with the c++ compiler. I simply commented them out as the cases where width == height == 0

vfx_ellipse.cpp:19:
                size_t ll = color;
                VFX_line_draw( pane, xc-width, yc-height, xc+width, yc+height, 0, reinterpret_cast<void*>(ll) );

vfx_ellipse.cpp:320:                    
                size_t ll = color;
                VFX_line_draw( pane, xc-width, yc-height, xc+width, yc+height, 0, reinterpret_cast<void*>(ll) );
extern LONG  VFX_line_draw (PANE *pane, LONG x0, LONG y0,
                                 LONG x1, LONG y1, LONG mode, void* parm);

$ c++ -v --> (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

Also removed the flag -Wno-unknown-warning-option from CMakeLists as this does not exist for the standard linux compiler.

Lastly, I could not link and I believe this could be my own cmake config/Linux config issue with linker paths:

$ make
[  3%] Built target windows
[ 23%] Built target mclib
[ 37%] Built target mlr
[ 42%] Built target gosfx
[ 62%] Built target stuff
[ 65%] Built target gui
[ 65%] Built target gameos_main
[ 71%] Built target gameos
[ 71%] Linking CXX executable mc2
/usr/bin/ld: cannot find -lSDL2::SDL2
/usr/bin/ld: cannot find -lSDL2::SDL2main
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/mc2.dir/build.make:1417: mc2] Error 1
make[1]: *** [CMakeFiles/Makefile2:321: CMakeFiles/mc2.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
$ ldconfig -p | grep SDL
    libSDL2_ttf-2.0.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2_ttf-2.0.so.0
    libSDL2_ttf-2.0.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2_ttf-2.0.so
    libSDL2_net-2.0.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2_net-2.0.so.0
    libSDL2_net-2.0.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2_net-2.0.so
    libSDL2_mixer-2.0.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2_mixer-2.0.so.0
    libSDL2_mixer-2.0.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2_mixer-2.0.so
    libSDL2_image-2.0.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2_image-2.0.so.0
    libSDL2_image-2.0.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2_image-2.0.so
    libSDL2_gfx-1.0.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2_gfx-1.0.so.0
    libSDL2-2.0.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2-2.0.so.0
    libSDL2-2.0.so.0 (libc6) => /lib/i386-linux-gnu/libSDL2-2.0.so.0
    libSDL2-2.0.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL2-2.0.so
    libSDL_ttf-2.0.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL_ttf-2.0.so.0
    libSDL_sound-1.0.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL_sound-1.0.so.1
    libSDL_mixer-1.2.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL_mixer-1.2.so.0
    libSDL_image-1.2.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL_image-1.2.so.0
    libSDL-1.2.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libSDL-1.2.so.0

Learning a lot. I hope I get there.

Thanks

alariq commented 3 years ago

Hi, as for vfx_ellipse.cpp errors, not sure why you have them. it is a aprt of original code and I have not seen this issue. Will try to reproduse.

SDL issue might be related to FindSDL.cmake.

I tihnk there is not a standard FindSDL.cmake anymore and in a custom one on the internet those targets are defined differently (stumbled upon this issue with my another project). I'll see what I can do about it, but a quick advice: look into FindSDL.cmake to see if they define link librarties as a SDL2::Main instead

burger-drip commented 3 years ago

Thanks for the suggestions. Still poking around.

So there are definite issues with the cmake rules.

From CMakeLists.txt, is this right though? include_directories(SD2::SDL2)

I wasn't sure if that requires a directory SDL2 in the local directory and references SDL2

I get the following messages about the SDL2::SDL2

CMake Warning (dev) at CMakeLists.txt:214 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "mc2" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?

Curiously found this project, which defined linking a little differently. I honestly thought cmakes was supposed to simplify linking, but it has been a strange dive into .cmake files on the internet https://github.com/microsoft/vcpkg/issues/13234

Just for reference, this is my cmake . output:

CMAKE library architecture: x86_64-linux-gnu
-- Target is 64 bits
Found SDL2 package -lSDL2
SDL libs are here: -lSDL2
OPENGL library found in 
GLEW library found in /usr/lib/x86_64-linux-gnu/libGLEW.so
Zlib library found in /usr/lib/x86_64-linux-gnu/libz.so
OpenGL library linking: 
OpenGL library include: /usr/include
Not win32 system
sdl2 prefix: /usr
SDL_LIBS: -lSDL2
zlib: /usr/lib/x86_64-linux-gnu/libz.so
-- Target is 64 bits
-- Configuring done
CMake Warning (dev) at CMakeLists.txt:214 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "mc2" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:214 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "mc2" links to target "SDL2::SDL2main" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at data_tools/CMakeLists.txt:17 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "makersp" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at data_tools/CMakeLists.txt:17 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "makersp" links to target "SDL2::SDL2main" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at data_tools/CMakeLists.txt:14 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "aseconv" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at data_tools/CMakeLists.txt:14 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "aseconv" links to target "SDL2::SDL2main" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at data_tools/CMakeLists.txt:11 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "pak" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at data_tools/CMakeLists.txt:11 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "pak" links to target "SDL2::SDL2main" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at data_tools/CMakeLists.txt:8 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "makefst" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at data_tools/CMakeLists.txt:8 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "makefst" links to target "SDL2::SDL2main" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at text_tool/CMakeLists.txt:7 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "text_tool" links to target "SDL2::SDL2" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at text_tool/CMakeLists.txt:7 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "text_tool" links to target "SDL2::SDL2main" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at Viewer/CMakeLists.txt:26 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "viewer" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at Viewer/CMakeLists.txt:26 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "viewer" links to target "SDL2::SDL2main" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /data/_build/mc2

Thanks, I'll try again next time I get a chance.

alariq commented 3 years ago

Issue with SDL2::SDL2 replated to the fact that find_package(SDL2 REQUIRED) diod not work out which is strange though because it shoule have complained about it (because it set to REQUIRED.

You should have FindSDL2.cmake in your system somewhere which should export this IMPORTED target

As I said, I'll have a look

burger-drip commented 3 years ago

Hi, thanks for the help. It compiles now!

I replaced the SDL2::SDL2 with ${SDL_LIBS} or ${SDL2_LIBRARIES}

Change 1)

Changing this statement in the top level CMakeLists.txt file: target_link_libraries(mc2 mclib gosfx mlr stuff gui gameos gameos_main windows ZLIB::ZLIB ${SDL_LIBS} GLEW::GLEW ${SDL2_mixer} ${ADDITIONAL_LIBS} OpenGL::GL)

Change 2)

$ pwd 
/data/_build/mc2/data_tools
$ diff CMakeLists.txt CMakeLists.txt.original 
9c9
< target_link_libraries(makefst mclib stuff gameos windows ZLIB::ZLIB ${SDL_LIBS} ${ADDITIONAL_LIBS})
---
> target_link_libraries(makefst mclib stuff gameos windows ZLIB::ZLIB SDL2::SDL2 SDL2::SDL2main ${ADDITIONAL_LIBS})
12c12
< target_link_libraries(pak mclib stuff gameos windows ZLIB::ZLIB ${SDL_LIBS} ${ADDITIONAL_LIBS})
---
> target_link_libraries(pak mclib stuff gameos windows ZLIB::ZLIB SDL2::SDL2 SDL2::SDL2main ${ADDITIONAL_LIBS})
15c15
< target_link_libraries(aseconv mclib gosfx mlr stuff gameos windows ZLIB::ZLIB ${SDL_LIBS} GLEW::GLEW ${SDL2_mixer} ${ADDITIONAL_LIBS} OpenGL::GL)
---
> target_link_libraries(aseconv mclib gosfx mlr stuff gameos windows ZLIB::ZLIB SDL2::SDL2 SDL2::SDL2main GLEW::GLEW ${SDL2_mixer} ${ADDITIONAL_LIBS} OpenGL::GL)
18c18
< target_link_libraries(makersp mclib stuff gameos windows ZLIB::ZLIB ${SDL_LIBS} ${ADDITIONAL_LIBS})
---
> target_link_libraries(makersp mclib stuff gameos windows ZLIB::ZLIB SDL2::SDL2 SDL2::SDL2main ${ADDITIONAL_LIBS})

Change 3)

I did the same for CMakeLists.txt in directory /data/_build/mc2/text_tools

Change 4)

For building gameos, that had many linking issues. I modified the CMakeLists.txt file as follows

include_directories("../include"  ".")

find_package(SDL2 REQUIRED)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(ZLIB REQUIRED)
include_directories(${SDL_INCLUDES})
include_directories(${OpenGL_INCLUDES})
include_directories(${GLEW_INCLUDES})
include_directories(${ZLIB_INCLUDES})

add_library(gameos ${SOURCES})
add_library(gameos_main ${MAIN_SRC} )
target_link_libraries(gameos ${SDL2_LIBRARIES} OpenGL::OpenGL ${ZLIB_LIBRARIES} ${GLEW_LIBRARIES} ${ADDITIONAL_LIBS} )

I think the problem may be using SDL2::SDL2 if it not recognised in a system config.

$ cmake --version
cmake version 3.16.3

$ aptitude versions libsdl2-dev
Package libsdl2-dev:                              
i   2.0.10+dfsg1-3 

Finally a compiled binary!


mc2: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=099d228903a956942649bc8f30e55e6ea41aaf56, for GNU/Linux 3.2.0, not stripped```

Thanks again!
alariq commented 3 years ago

No problem, I am using modern style Cmake syntax therefore I am using import targets (this ethings like SDL::SDL), as I suggested, your CMake could not find it, so you had errors, ut I also use oldmethod which fills in things like ${SDL_INCLUDES} so by switching to this it worked.

Anyway, glad that you've magaged to compile it. Now try to run :P you'll need to prepare the data, although it should be smooth as soon as you've built all the required tools. Data build only uses plain old make

alariq commented 3 years ago

I've done some change to build scripts now SDL2 problem should be gone even on the systems where CMake has troubles finding it