New to Ubuntu/Linux need help linking

Hello, I recently got Ubuntu and I do not know how to link libraries or add search paths for headers. I use G++ (which is what I used on WIndows, but the commands do not seem to work)

I am trying to use SFML and Boost.
SFML is in home/failbit/Libraries/SFML-1.6 and includes lib (library files) and include (header files)

I tried compiling with:
 
g++ main.cpp -Ihome/failbit/Libraries/SFML-1.6/include -Lhome/failbit/Libraries/SFML-1.6/lib -lsfml-system -lsfml-window -lsfml-graphics


I get errors because g++ cannot find the headers or the libs.

this is my test program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main(int argc, char** argv) {
	sf::RenderWindow window(sf::VideoMode(640, 480, 32), "sfTest");
	window.SetFramerateLimit(60);
	
	while ( window.IsOpened() ) {
		// Check for events
		sf::Event e;
		while ( window.GetEvent(e) )
			if ( e.Type == sf::Event::Closed )
				window.Close();

		// CLear the window buffer
		window.Clear();

		sf::String str;
		str.SetText("sf::String Text");

		window.Draw(str);

		window.Display();
	}

	return 0;
}
Last edited on
You forgot a / in front of home.
But there's no need to use a custom install anyway (unless you want to modify the SFML library).
Just install the package libsfml-dev and then you won't need to specify any additional paths.
Thanks it worked :D
BUt now I need opengl can I install it with:
sudo apt-get install libopengl
Last edited on
If you install freeglut3-dev, you'll get the whole thing: Mesa GL & GLU and GLUT.
If you need GLEW, that would be libglew1.5-dev.
It works! Thanks for your help Athar.
I have one more question. It is possible to use -L,-l, and -I in Linux just like in Windows?

How would I direct g++ to the files if it is possible?
Eg:
I have SFML in home/failbit/Libraries/SFML-1.6/

Would I use:
g++ main.cpp -L/home/failbit/Libraries/SFML-1.6/lib
?
Last edited on
Yes, that's how it works.
But as mentioned, you only need to do that for your own libraries. Libraries installed via the package manager go to /usr/lib, where the linker will look without being told to.
try this:
create a file called Makefile in your program directory.

Just put this in it:
(first check I got it right of course)

1
2
3
4
5

LDLIBS=-lsfml-system -lsfml-window -lsfml-graphics
LDFLAGS=-L/home/failbit/Libraries/SFML-1.6/lib
CFLAGS=-I home/failbit/Libraries/SFML-1.6/include


your file is called main.cpp?

so type:

make main and something like this should happen:

1
2
3
[billy@elmer:0]$ make main
g++   -L/home/failbit/Libraries/SFML-1.6/lib  main.cpp  -lsfml-system -lsfml-window -lsfml-graphics -o main

simples...

look for gnu make on your favourite search engine.

Or you can export them as variables and not even need a makefile.
Topic archived. No new replies allowed.