gcc won't compile SDL C Program (undefined reference to SDL functions)

前端 未结 5 1556
栀梦
栀梦 2021-01-14 18:32

I recently moved to linux and i\'m having an issue with compiling SDL C programs using gcc.

The command i\'m using:

gcc `sdl-config --cflags --libs`          


        
5条回答
  •  深忆病人
    2021-01-14 18:43

    Order of arguments to gcc matters a lot.

    Read about Invoking GCC (and documentation of binutils, which gcc uses). Then replace

     gcc `sdl-config --libs` -o main main.o
    

    with

     gcc main.o  `sdl-config --libs` -o main
    

    Better yet, learn how to use GNU make (it is often using GNU bash) and use a Makefile inspired by this answer...

    Also, always pass -Wall -g to gcc until your program is bug-free (then use -Wall -O2)

    Take inspiration from open source programs on github or gitlab using SDL. Consider also using other open source libraries and frameworks, such as Qt, SFML, GTKmm, etc... And study their example code.

提交回复
热议问题