SFML community forums
Help => General => Topic started by: Anonymous on July 10, 2014, 05:19:06 pm
-
Hi,
I have been developing an audio library based in C. I have then been developing an application which uses this library based in C++, and this C++ application uses the SFML libraries to display information from my library onto the screen. I was previously using Visual C++ to create my c library code and cpp application code, however I realised that all of it was being passed through a c++ compiler, and I want my library to be purely C code so I am taking to doing everything outside of the VC++ IDE.
I have learnt how to create a .o file from my C code. I then use extern "C" { #include analyser.h }
in my main.cpp application, and use the command g++ -o myAnalyser main.cpp analyser.o
to link my c++ application with the c library.
The next step I need to do is to get my main.cpp application linking with all the SFML files, so that the program will run correctly. All of my settings were managed by VC++, the imports I have in my main.cpp file are: #include <SFML/Graphics.hpp> #include <SFML/Audio.hpp> #include <SFML/System.hpp>, and I have also had to include the libsndfile-1.dll and openal32.dll files in the directory of which my application was built to run.
If anyone would be able to help me compiling my cpp code with MinGW with the relevant compiler flags, instead of having to rely on the properties I have set in VC++ that would be great.
Many thanks,
Mark.
-
In my opinion, the first step should be to pick/adopt a cross platform build system to manage your build process.
Personally I recommend SCons (http://www.scons.org/) for this.
Some people prefer CMake (http://cmake.org/), qmake (http://qt-project.org/doc/qt-4.8/qmake-manual.html) or plain old classical make (http://www.gnu.org/software/make/) (they are wrong of course, but I respect their right to choose ;) ).
Whatever you pick, the important thing is to pick something and then learn your tool properly - it will make your life a lot easier going forward when you want to juggle multiple compilers and multiple operating systems.
Even if you only ever want to use one compiler on one OS, using an existing well-known and feature full build system will help you compared to whatever ad-hoc thing you can create yourself.
-
Hi,
To get started I am trying to compile a simple SFML app in bash with MinGW (g++):
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
I have been following this tutorial: SFML and Linux (http://sfml-dev.org/tutorials/2.1/start-linux.php)
My code compiled with g++ -c main.cpp -I/c/SFML-2.1/include
but then when I try to link the compiled file to the libraries I get an error. I use the command: g++ main.o -o sfml-app -L/c/SFML-2.1/lib -lsfml-graphics -lsfml-window -lsfml-system
but I get the following result:
(http://i.imgur.com/ljDoRZD.png)
I think this is because I am not on linux, I am on windows. And so I am not supposed to link to .so files, the files I want to link to in SFML-2.1/lib are Object File Library files. If anyone would be able to help me create an executable for this simple SFML code on MinGW that would be very helpful.
Thanks,
Mark
-
What MinGW version are you using? From where did you get SFML?
-
I am using 4.8.1 and I am using SFML 2.1 for Visual C++ 2010, which might be the problem. Looking at the downloads page I guess that I need the SFML GCC 4.7 MinGW for Windows? I was using visual c++ but I am trying to switch to compiling without an IDE.
-
SFML needs to be compiled with the same compiler, you're using to compile your application and since SFML doesn't provide packages for GCC 4.8.1, you'll have to rebuild SFML on your own.
-
Okay, I've downloaded the sources, how will I go about compiling with gcc 4.8.1, are there any tutorials because I am not sure what to do?
Thanks for the help
-
If you had spent 5 seconds on http://www.sfml-dev.org/ looking for it you'd have found: http://www.sfml-dev.org/tutorials/2.1/compile-with-cmake.php
SFML is extremely well documented.
-
I have been looking on the tutorials because they are very useful. I just didn't realise that CMake was what I needed for this task.
-
I have gone through with CMake and installed both the static and dynamic libraries for debug and release modes in the directory C:/Program Files (x86)/SFML
I have now tried to follow the tutorial SFML and Linux (http://www.sfml-dev.org/tutorials/2.1/start-linux.php), replacing <sfml-install-path> with /c/"Program Files (x86)"/SFML (not sure if I need the brackets but I used them due to the spacing).
Commands used to try and create an executable program that links in to the SFML files:
g++ -c main.cpp -I<sfml-install-path>/include
g++ main.o -o sfml-app -L<sfml-install-path>/lib -lsfml-graphics -lsfml-window -lsfml-system
export LD_LIBRARY_PATH=<sfml-install-path>/lib && ./sfml-app
I manage to generate a .o and then an executable file, however at runtime I get the message "The program can't start because sfml-graphics-2.dll is missing from your computer. Try reinstalling the program to fix this problem." The sfml-graphics-2.dll, along with the other release and debug dll files are found in /c/Program Files (x86)/SFML/bin, so I am unsure where I am supposed to link these, and what I need to do to get my program running.
Thanks for the continued help, I feel like I'm almost there.
-
From the tutorials about Code::Blocks and VS:
Compile it, and if you linked to the dynamic version of SFML, don't forget to copy the SFML DLLs (they are in <sfml-install-path/bin>) to the directory where your compiled executable is.
-
Thanks very much, I knew I was almost there! Working with SFML really is a dream with the amount of help in the documentations, tutorials and on the forums.