2

I am doing an SDL project for uni and made a fully working program in visual studio on windows, however when i put the program on Linux (required for the demo) i get a segmentation fault. I am wondering whether its my cmakelist file that is wrong due to the gdb output mainly being things in sdl libraries but i am really unsure as i am new to cmake.

Using gdb i have tried to track down the segmentation fault but it hasn't been much help! All that i have changed from the windows version is that i've made a cmakelists.txt and changed the includes in my header files for SDL on linux.

GDB Output:

#0  0x00007fffed4f521e in ?? ()
#1  0x00007ffff4f5bac2 in XCloseIM () from /lib64/libX11.so.6
#2  0x00007ffff7b67c44 in X11_VideoQuit () from /lib64/libSDL2-2.0.so.0
#3  0x00007ffff7b37d4e in SDL_VideoQuit_REAL () from /lib64/libSDL2-2.0.so.0
#4  0x00007ffff7aaffc5 in SDL_QuitSubSystem_REAL () from /lib64/libSDL2-2.0.so.0
#5  0x00007ffff7ab00e8 in SDL_Quit_REAL () from /lib64/libSDL2-2.0.so.0
#6  0x000000000040266f in close () at /home/csunix/sc18mk/Documents/Programming Project/SDL/SDL FOR C/main.c:105
#7  0x00007fffed144b13 in _dbus_close () from /lib64/libdbus-1.so.3
#8  0x00007fffed13c2c6 in socket_disconnect () from /lib64/libdbus-1.so.3
#9  0x00007fffed13b0fb in _dbus_transport_disconnect.part.5 () from /lib64/libdbus-1.so.3
#10 0x00007fffed125ee2 in _dbus_connection_close_possibly_shared_and_unlock () from /lib64/libdbus-1.so.3
#11 0x00007ffff7b759d6 in SDL_DBus_Quit () from /lib64/libSDL2-2.0.so.0
#12 0x00007ffff7b37d4e in SDL_VideoQuit_REAL () from /lib64/libSDL2-2.0.so.0
#13 0x00007ffff7aaffc5 in SDL_QuitSubSystem_REAL () from /lib64/libSDL2-2.0.so.0
#14 0x00007ffff7ab00e8 in SDL_Quit_REAL () from /lib64/libSDL2-2.0.so.0
#15 0x000000000040266f in close () at /home/csunix/sc18mk/Documents/Programming Project/SDL/SDL FOR C/main.c:105
#16 0x00007ffff4cefc1b in xcb_disconnect () from /lib64/libxcb.so.1
#17 0x00007fffdcab539d in pa_client_conf_from_x11 () from /usr/lib64/pulseaudio/libpulsecommon-10.0.so
#18 0x00007fffdca76050 in pa_client_conf_load () from /usr/lib64/pulseaudio/libpulsecommon-10.0.so
#19 0x00007fffdccee884 in pa_context_new_with_proplist () from /lib64/libpulse.so.0
#20 0x00007ffff7b5aa2e in ConnectToPulseServer_Internal () from /lib64/libSDL2-2.0.so.0
#21 0x00007ffff7b5b0c9 in PULSEAUDIO_Init () from /lib64/libSDL2-2.0.so.0
#22 0x00007ffff7ab448c in SDL_AudioInit_REAL () from /lib64/libSDL2-2.0.so.0
#23 0x00007ffff7aafcb7 in SDL_InitSubSystem_REAL () from /lib64/libSDL2-2.0.so.0
#24 0x000000000040292f in init () at /home/csunix/sc18mk/Documents/Programming Project/SDL/SDL FOR C/init.c:13
#25 0x0000000000402694 in main (argc=1, args=0x7fffffffdbd8) at /home/csunix/sc18mk/Documents/Programming Project/SDL/SDL FOR C/main.c:111
(gdb) frame 6
#6  0x000000000040266f in close () at /home/csunix/sc18mk/Documents/Programming Project/SDL/SDL FOR C/main.c:105
105     SDL_Quit();
(gdb) frame 15
#15 0x000000000040266f in close () at /home/csunix/sc18mk/Documents/Programming Project/SDL/SDL FOR C/main.c:105
105     SDL_Quit();
(gdb) frame 25
#25 0x0000000000402694 in main (argc=1, args=0x7fffffffdbd8) at /home/csunix/sc18mk/Documents/Programming Project/SDL/SDL FOR C/main.c:111
111     if (init()) {
(gdb) frame 24
#24 0x000000000040292f in init () at /home/csunix/sc18mk/Documents/Programming Project/SDL/SDL FOR C/init.c:13
13      if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1) {

CMakeLists.txt:

project(SDL)

#set( CMAKE_BUILD_TYPE Release)
set( CMAKE_BUILD_TYPE Debug)

cmake_minimum_required(VERSION 2.6)
set (CMAKE_C_FLAGS "-std=c99 -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL_mixer -g")

add_executable(kraken main.c init.c kraken.c worldObject.c menu.c leaderboard.c display.c)

set_property(TARGET kraken PROPERTY C_STANDARD 99)
Mark Keast
  • 23
  • 2
  • 1
    The problem is with the code in your program, but we can't see it. Make sure you deallocate things in the reverse order they were allocated in and be aware if the ownership of any of your allocated data is passed to the receiver so that you don't try to double free it. If you need more help, work on a [mcve]. Just because you don't witness a crash on Widows doesn't mean your program is correct. Learn to use Valgrind. – Retired Ninja Apr 27 '19 at 20:11
  • 2
    Possible duplicate of [Odd segmentation fault with CC/GCC but not G++ (C/SDL2/Linux)](https://stackoverflow.com/questions/31304591/odd-segmentation-fault-with-cc-gcc-but-not-g-c-sdl2-linux) – genpfault Apr 28 '19 at 03:01

1 Answers1

2
#14 0x00007ffff7ab00e8 in SDL_Quit_REAL () from /lib64/libSDL2-2.0.so.0
#15 0x000000000040266f in close () at /home/csunix/sc18mk/Documents/Programming Project/SDL/SDL FOR C/main.c:105
#16 0x00007ffff4cefc1b in xcb_disconnect () from /lib64/libxcb.so.1

xcb_disconnect() has no business calling your version of close(). Rename it so it doesn't conflict with POSIX's close() name or declare it static.

genpfault
  • 51,148
  • 11
  • 85
  • 139