SDL configuration in Eclipse IDE

给你一囗甜甜゛ 提交于 2019-12-05 00:03:02

问题


I am trying to get a OpenGL code run on Eclipse in Linux x86 environment (ubuntu): http://nehe.gamedev.net/tutorial/vertex_buffer_objects/22002/ The code would run properly after I input in the command line with

g++ main.cpp error.cpp lesson45.cpp -o lesson45 -L/usr/X11R6/lib/ -lGL -lGLU sdl-config --cflags --libs

Which is the instruction from the make file. Now I'm attempting to get the code run on Eclipse, I know I must set up linker libraries GL and GLU and linker library directory /usr/X11R6/lib/. However, with respect to sdl-config --cflags --libs, I am not sure how to configure it within Eclipse.


回答1:


Create a new C++ project (File > New > C++ Project). You will need to pick a toolchain - Linux GCC.

If you want to use C++11 do the following:

  1. Right click your Project under “Package Explorer” and select Properties.
  2. Select (C/C++ Build > Settings > GCC C++ Compiler > Miscellaneous)
  3. Under “Other flags” add: -std=c++0x
  4. Click Apply then OK

Configure Eclipse to use SDL2

  1. Right click your Project under “Package Explorer” and select Properties.
  2. Select (C/C++ General > Paths and Symbols > Libraries)
  3. Click “Add” and add “SDL2″ and click OK
  4. Click “Add” and add “SDL2main” and click OK

This process has been tested and confirmed working although I don't take any credit for it. Information sourced from HERE




回答2:


I'll attempt to provide a more thorough answer from a combination of the previously given suggestions. On a Fedora22 system with Eclipse Mars version 4.5.1 this worked for me. As suggested by @Zammalad, with a few changes, first

  • Create a new C++ project (File > New > C++ Project).
  • You will need to pick a toolchain - Linux GCC.

If you want to use C++11 do the following:

  • Right click your Project under “Package Explorer” and select Properties.
  • Select (C/C++ Build > Settings > GCC C++ Compiler > Dialect)
  • Under “Language standard” select: "ISO C++11 (-std=c++0x)". Click Apply, then OK.

Configure Eclipse to use SDL2

At this step, I'd suggest taking @esperanto's approach to use the system's terminal/shell to find out or verify the existence/location of the necessary files/libraries for SDL2 on your system.

First, if you want to find the location of the necessary libraries on your system, executing the following in the terminal will provide you with the "include" location and other compiler/preprocessor flags

$ sdl2-config --cflags

Similarly, to list the libraries/linker-flags

$ sdl2-config --libs

For example, on my Fedora22 (64bit) system, the output looks like this

$ sdl2-config --cflags --libs
-I/usr/include/SDL2 -D_REENTRANT
-lSDL2 -lpthread

You can test the compilation in a separate temporary directory without the eclipse-related project files--i.e. only the source files--like this:

$ mkdir /tmp/testing
$ cp -r main.cpp error.cpp lesson45.cpp /tmp/testing/.
$ cd /tmp/testing
$ g++ `sdl2-config --cflags --libs` -o lesson45 main.cpp error.cpp lesson45.cpp

Now, to use the SDL2 libraries/paths within Eclipse, add the necessary libraries from the sdl2-config --libs output

  • Right click your Project under “Package Explorer” and select Properties.
  • Select (C/C++ General > Paths and Symbols > Libraries)
  • Click “Add” and type SDL2 and click OK
  • Click “Add” and type pthread and click OK

To add the preprocessor directive from the sdl2-config --cflags output

  • Right click your Project under “Package Explorer” and select Properties.
  • Select (*C/C++ Build > Settings > GCC C++ Compiler > Preprocessor)
  • Under "Defined symbols (-D)", Click the "Add" icon
  • Type _REENTRANT and click OK



回答3:


In case you cannot find anything more civilized to configure Eclipse, you can always extract this information from the sdl-config invocation and configure the settings by hand:

## Compiler flags
$ sdl-config  --cflags
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT

## Linker flags
$ sdl-config  --libs
-L/usr/lib/x86_64-linux-gnu -lSDL


来源:https://stackoverflow.com/questions/15561458/sdl-configuration-in-eclipse-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!