Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Linux setup troubles  (Read 12092 times)

0 Members and 1 Guest are viewing this topic.

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Linux setup troubles
« on: March 10, 2014, 11:11:23 pm »
Hey everybody,

So I'm trying to get my C++ development projects set up on Crunchbang Linux. I've downloaded the SFML libraries needed, and I'm trying to run the basic functionality test, ie

#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 then go to the terminal & try

g++ -c Testrun.cpp

as the tutorial says, but I get

Testrun.cpp: In function ‘int main()’:
Testrun.cpp:6:5: error: ‘CircleShape’ is not a member of ‘sf’
Testrun.cpp:6:21: error: expected ‘;’ before ‘shape’
Testrun.cpp:7:5: error: ‘shape’ was not declared in this scope
Testrun.cpp:9:19: error: ‘class sf::RenderWindow’ has no member named ‘isOpen’
Testrun.cpp:12:23: error: ‘class sf::RenderWindow’ has no member named ‘pollEvent’
Testrun.cpp:14:23: error: ‘class sf::Event’ has no member named ‘type’
Testrun.cpp:15:24: error: ‘class sf::RenderWindow’ has no member named ‘close’
Testrun.cpp:18:16: error: ‘class sf::RenderWindow’ has no member named ‘clear’
Testrun.cpp:19:16: error: ‘class sf::RenderWindow’ has no member named ‘draw’
Testrun.cpp:20:16: error: ‘class sf::RenderWindow’ has no member named ‘display’
 

Which appears to indicate that the hierarchy of #includes has screwed up somewhere? Ive also noticed that g++ needs cpp files included explicitly (which was not necessary in MSVC++ 2010, oddly enough), maybe I need to do something similar here?

Thanks for any help in getting this running. :)

Quote
The computer is mightier than the pen, the sword, and usually the programmer.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Linux setup troubles
« Reply #1 on: March 10, 2014, 11:21:53 pm »
You're using SFML 1.6. Download SFML from the homepage or GitHub, not from the package manager.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Linux setup troubles
« Reply #2 on: March 10, 2014, 11:27:02 pm »
Testrun.cpp: In function ‘int main()’:
Testrun.cpp:6:5: error: ‘CircleShape’ is not a member of ‘sf’
Testrun.cpp:6:21: error: expected ‘;’ before ‘shape’
Testrun.cpp:7:5: error: ‘shape’ was not declared in this scope
Testrun.cpp:9:19: error: ‘class sf::RenderWindow’ has no member named ‘isOpen’
...
 

Which appears to indicate that the hierarchy of #includes has screwed up somewhere?
Are you sure you have SFML 2.1 installed and not, say, 1.6?  Double check.


Ive also noticed that g++ needs cpp files included explicitly (which was not necessary in MSVC++ 2010, oddly enough), maybe I need to do something similar here?
I have no idear what you mean by "g++ needs cpp files included explicitly" - could you elaborate?

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Re: Linux setup troubles
« Reply #3 on: March 10, 2014, 11:33:09 pm »
You're using SFML 1.6. Download SFML from the homepage or GitHub, not from the package manager.

Right. Where should I unpack the tar.gz so that I wont need to specify the installation directory?
Quote
The computer is mightier than the pen, the sword, and usually the programmer.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Linux setup troubles
« Reply #4 on: March 10, 2014, 11:39:27 pm »
You're using SFML 1.6. Download SFML from the homepage or GitHub, not from the package manager.

Right. Where should I unpack the tar.gz so that I wont need to specify the installation directory?

Doesn't matter where you unpack and build it.
What matters is where you choose to install it. If it goes into one of the standard locations like /lib/ /usr/lib or /usr/local/lib , then most distros are set up so that everything will "just work"(TM).

Ohh and uninstall that SFML 1.6 you have (unless something else needs it) just to avoid it getting in the way :-)

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Re: Linux setup troubles
« Reply #5 on: March 10, 2014, 11:53:15 pm »
Ummm no such luck. I tried unpacking the contents and moving them to /usr/lib/SFML-2.1, but I didn't have any luck. Where is it supposed to look for the include files?
Quote
The computer is mightier than the pen, the sword, and usually the programmer.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Linux setup troubles
« Reply #6 on: March 10, 2014, 11:56:57 pm »
Taking a wild quess as to what you mean by
Quote
Ive also noticed that g++ needs cpp files included explicitly (which was not necessary in MSVC++ 2010, oddly enough)
I guess that you mean that you had to type "g++ -c Testrun.cpp" (listing the source file for the compiler explicitly there) while in VS you just clicked a button to build.
Well, if you call the Visual Studio compiler (cl.exe) directly on the commandline on a Windows machine then you also have to explicitly list the files you want it to compile - no different than GCC.

The difference is probably that you are mixing up the direct invocation of the compiler (g++ in this case) and the invocation of a build system (Visual Studio/msbuild on Windows).

The thing is. On Windows:
Visual Studio creates "project files " which are XML files that describe what to build and how to build it (these can also be run by "msbuild" if you don't have Visual Studio but just the Windows SDK). The build system then invokes the compiler (cl.exe) with an explicit commandline, passing it options such as optimization level to use, what warning level to use, what source files to build etc etc - just like that g++ commandline you showed us.

On Linux:
You can have a build system too :-)  If you prefer an IDE like Visual Studio then Qtcreator, Code::Block and Eclipse (with cdt) are common options that many people like. If you prefer to have more direct control, then you can use something like SCons, CMake or plain old make (these 3 have the advantage that if you have set your project up to build with either one then they can do a build from the same definition files on Windows, Linux, OS X and several other platforms - that's something you don't get with VS project files).
All of these do the same basic thing as what you are used to on Windows; they have some file(s) that describe what to build and how to build it and a way for you to tell them to "please do a build" and then they invoke the commandline compiler explicitly for each and every source file and passes it options.
(my personal preference is SCons)

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Linux setup troubles
« Reply #7 on: March 11, 2014, 12:10:31 am »
Ummm no such luck. I tried unpacking the contents and moving them to /usr/lib/SFML-2.1, but I didn't have any luck. Where is it supposed to look for the include files?
It's very simple (there are tutorials describing this), but here it is in a nutshell:

$ git clone https://github.com/SFML/SFML.git
(...output from git...)
$ cd SFML/
$ mkdir build
$ cd build
$ cmake ..
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
(...cut much more cmake output...)
$ make
Scanning dependencies of target sfml-system
[  1%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.o
[  2%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Err.cpp.o
(...cut lots of output about building and linking files...)
[100%] Built target sfml-audio
$ sudo make install
(...after entering password, lots of lines about installing stuff)
$
 
You are all done.
See? Easy. Takes all of 5 minutes - tops. :)

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Re: Linux setup troubles
« Reply #8 on: March 11, 2014, 12:20:49 am »
mmhmm, works up until the cmake part. I'm running crunchbang, which I think has issues with C support. Maybe I can use something else to build it?
Quote
The computer is mightier than the pen, the sword, and usually the programmer.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Linux setup troubles
« Reply #9 on: March 11, 2014, 12:23:57 am »
mmhmm, works up until the cmake part.
Well, you have to have cmake installed of course (and make and a bunch of other dev tools for that matter), but I assumed you could take care of that bit yourself.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Linux setup troubles
« Reply #10 on: March 11, 2014, 12:52:53 am »
Just for your information:

The .hpp files go in /usr/include, the .so's or .a's go in /usr/lib.

For the .hpp's, I usually put them in their own folder. For example:


Then I just dump all the library files in /usr/lib.

So, in your main.cpp, you would say:
#include <SFML/Window.hpp>
...etc
 

Also, cmake is not a default program usually. You'll have to install it.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Linux setup troubles
« Reply #11 on: March 11, 2014, 01:00:27 am »
Just for your information:

The .hpp files go in /usr/include, the .so's or .a's go in /usr/lib.
Yes, obviously.
But "make install" takes care of that bit for you.

Sorry if I sound harsh, I'm just at the end of my patience with basic questions today (nothing to do with you nor the SFML forum, so sorry - your advice is helpful and good).
I'm just grumpy since all of this is basic knowledge if you are serious about developing software and there are even tutorials and HOWTO's that explain it in detail if you are new to it.
« Last Edit: March 11, 2014, 01:06:43 am by Jesper Juhl »

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Linux setup troubles
« Reply #12 on: March 11, 2014, 01:47:34 am »
He asked, I was just answering. And yes, it does.

And I understand, no problems here!

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Re: Linux setup troubles
« Reply #13 on: March 14, 2014, 12:10:05 am »
Just for your information:

The .hpp files go in /usr/include, the .so's or .a's go in /usr/lib.
Yes, obviously.
But "make install" takes care of that bit for you.

Sorry if I sound harsh, I'm just at the end of my patience with basic questions today (nothing to do with you nor the SFML forum, so sorry - your advice is helpful and good).
I'm just grumpy since all of this is basic knowledge if you are serious about developing software and there are even tutorials and HOWTO's that explain it in detail if you are new to it.

No worries, I apologize for asking about stuff like this without doing the essential groundwork beforehand. Are there any specific tutorials that you would highly reccomend on getting development set up on linux?

A bit of an aside, but I was also thinking that the problem might as well be cut off at the source if the package manager in question wasn't distributing an old version of SFML. If I bring this up with the Crunchbang development team, I assume they'll probably be able to update it to 2.1?

Thanks for the suggestion dabbertorres, will try that as soon as I can.
Quote
The computer is mightier than the pen, the sword, and usually the programmer.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Linux setup troubles
« Reply #14 on: March 14, 2014, 01:02:30 am »
No worries, I apologize for asking about stuff like this without doing the essential groundwork beforehand.
No need. I am the one to apologize here. I was having a bad day and should have just kept my mouth shut. Sorry.

Are there any specific tutorials that you would highly reccomend on getting development set up on linux?
Well, the SFML tutorials do a pretty good job for the SFML part in my opinion.

And most tools (like gcc, ld, gdb, make, cmake, scons, clang, valgrind etc) have pretty good documentation both in their respective man pages and online on their websites.

The Program Library HOWTO does a pretty good job at explaining the basics of shared libraries, static libraries, dlopen() and that sort of stuff.

This is a pretty nice intro to reverse debugging with gdb 7: http://jayconrod.com/posts/28/tutorial-reverse-debugging-with-gdb-7

Just a few bits.

 

anything