📜 ⬆️ ⬇️

Setting up a C ++ project in Eclipse using the example of an SFML application

Good day to all! When setting up a project in Eclipse, I encountered several problems. After trying to find a solution to these problems, I found obvious tips on foreign forums that did not solve the problem. Scratching the back of my head, I began to solve the problems myself. In this article I will describe in detail the configuration of Eclipse CDT, MinGW, the connection of headers and libraries. The article is designed for beginners.

Definitions


Eclipse CDT is an integrated development environment for C and C ++ based on the Eclipse platform.

MinGW is a compiler, the native GNU Compiler Collection (GCC) program port under Microsoft Windows, along with a set of freely available import libraries and header files for the Windows API. MinGW allows developers to create native Microsoft Windows applications.

SFML is a free cross-platform multimedia library written in C ++.
')

Installing Eclipse and MinGW


Eclipse requires Java .

Download the Eclipse CDT from the official site and unpack it at any convenient place, for example C:\eclipse . Run eclipse.exe , if everything worked, fine.

Next, download the installer MinGW . Run it. We see a window with a description, click Install . If necessary, change the installation location and click Continue .

Note to install mingw-32-base and mingw-gcc-g ++.



After that click Installation -> Apply Changes. In the window that opens, click Apply and wait for the components to load and install. When the installation is complete, download msys . I think when installing problems will not arise. Now we need to add the path to the bin MinGW folder and the bin msys folder to the Path system variable.

I did it like this: d:\MinGW\bin\;d:\msys\1.0\bin\

Swing SFML MinGW , and unpack anywhere.
At this training is over.

Create and configure a C ++ project


Launch Eclipse, click File -> New -> C ++ Project. Create a Hello World project and select MinGW as in the picture.



Next PCM on the created project -> Properties, open C / C ++ Build -> Settings -> Tool Setting -> GCC C ++ Compiler -> Includes.
1. Click Add.
2. Select the includes folder from the directory where we unpacked SFML.



After that, go to the Preprocessor item and add SFML_DYNAMIC in the Defined Symbols.

Here we come to the point where I got the first error. If you connect a library with the .a extension through MinGW C ++ Linker -> Libraries, nothing will work. These libraries need to be connected via the MinGW C ++ Linker -> Miscellaneous as the Other Object. Specify the path to the libraries SFML, you need to connect libsfml-graphics.a, libsfml-window.a, libsfml-main.a



Build the project


Replace all the code in the automatically created .cpp with this:

 #include "SFML/Graphics.hpp" int main() { sf::RenderWindow window(sf::VideoMode(640, 480), "Test"); while(window.isOpen()){ sf::Event event; while(window.pollEvent(event)){ if(event.type == sf::Event::Closed){ window.close(); } window.clear(); window.display(); } } return 0; } 


Click Build

Everything will gather successfully but will not work, because there are no dll. We copy everything from the bin folder in the SFML directory to the Debug folder of our project.
Now click PCM on the .exe file that is located in the Debug folder of our project, select Run As -> Run Configurations, click C / C ++ Application and click New launch configuration, then click Run without changing anything.



After that, you can start the project using Ctrl + F11 or the corresponding icon on the toolbar.

We see a window with a black background, everything works.

PS Wrote an article a long time ago, and forgot about it =) Something could become outdated.

Source: https://habr.com/ru/post/241133/


All Articles