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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jakobnator

Pages: [1]
1
General / Re: Trouble linking libraries with Cmake
« on: November 23, 2016, 04:17:21 am »
Ok I went back and built SFML myself with the static options now my Cmake file is saying that it can't find the dependencies...

Code: [Select]
Error:SFML found but some of its dependencies are missing ( FreeType libjpeg OpenAL Ogg Vorbis VorbisFile VorbisEnc FLAC)
Is there a flag in cmake I am missing? Or is there a variable in cmakelist that I need to find the external dependencies?

EDIT: Nevermind I found it I had to point to the /install/ directory of my SFML folder based on the tutorial.

MAN was that a pain, I got it working now but I know very little on the in betweens of programming with cmake....

For future people trying to get Clion to work with SFML let me make it as cut and dry as possible.....

1. Download SFML source and put it in a folder.
2. Follow THIS:https://github.com/SFML/SFML/wiki/Tutorial:-Build-SFML-with-a-MinGW-Compiler
Cmake should look like this before generating makefiles->https://i.imgur.com/EHetsLR.png
3. Create a new Clion project and inside the project folder make another folder named cmake_modules and inside that create a file named FindSFML.cmake.
4. Inside FindSFML.cmake copy and paste the code for it found on github (The file is FindSFML.cmake)
5.Use the generic green circle code in the other tutorials for your main.cpp just to see if it's working.
6.Create another file inside your project folder named CMakeList.txt and post this code inside it
Code: [Select]
cmake_minimum_required(VERSION 3.2)
project(SFMLdemo)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")

# Set default build type explicitly to Release
if (NOT CMAKE_BUILD_TYPE)
    set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build type." FORCE)
endif (NOT CMAKE_BUILD_TYPE)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/)

if(NOT SFML_ROOT)
    set(SFML_ROOT "C:/SFML-2.4.1-build/install")
endif()

# Find SFML
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML REQUIRED COMPONENTS audio graphics window system)

if(NOT SFML_FOUND)
    message(FATAL_ERROR "SFML couldn't be located!")
endif()


include_directories(${SFML_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

set(SOURCE_FILES main.cpp)

add_executable(SFMLdemo ${SOURCE_FILES})

target_link_libraries(SFMLdemo ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

Anywhere you see SFMLDemo replace with your project name, and change the SFML_ROOT to your SFML root directory.
Boom. done.

Looks easy after doing it but a lot can go wrong. I might never fully understand why you can't just have a text file that states where SFML is, debug or release, and static or dyanmic linking. But I guess that's what cmake is, still not sure whats going on with the hiearchy of .cmake and .txt files either.... /noob rant

Thanks for the help though!


2
General / Re: Trouble linking libraries with Cmake
« on: November 22, 2016, 04:09:03 am »
Thank you for your help! I tried switching the order of the find_package() and now it just says
Code: [Select]
Error:Could NOT find SFML (missing: SFML_WINDOWS_LIBRARY)(not when compiling just when its rechecking the cmakelist file)

When I tried modifying your Cmakelist.txt I got a bunch of undefined reference errors ( still can't locate SFML?)
Code: [Select]
CMakeFiles\SFMLdemo.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x84): undefined reference to `sf::String::String(char const*, std::locale const&)'
Here is what I tried to do with your code, not very familiar with cmake syntax so it might be incorrect.

Code: [Select]
cmake_minimum_required(VERSION 3.2)
project(SFMLdemo)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")

# Set default build type explicitly to Release
if (NOT CMAKE_BUILD_TYPE)
    set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build type." FORCE)
endif (NOT CMAKE_BUILD_TYPE)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/)

if(NOT SFML_ROOT)
    set(SFML_ROOT "C:/SFML-2.4.1")
endif()

# Find SFML
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML REQUIRED COMPONENTS audio graphics window system)

if(NOT SFML_FOUND)
    message(FATAL_ERROR "SFML couldn't be located!")
endif()


include_directories(${SFML_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

set(SOURCE_FILES main.cpp)

add_executable(SFMLdemo ${SOURCE_FILES})

target_link_libraries(SFMLdemo ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

# Install executable
install(TARGETS SFMLdemo
        RUNTIME DESTINATION .
        )

# Install game data
install(DIRECTORY bin/res
        DESTINATION .
        )

3
General / Trouble linking libraries with Cmake
« on: November 21, 2016, 11:21:56 pm »
I am having issues trying to get SFML to work using Cmake. I have no experience with cmake, but for the past 24 hours have been trying to follow a scatter of different tutorials for different systems and forum posts but no clear setup on how to get an already compiled version of SFML to work with Clion. What I do know is that I need to setup FindSFML.cmake file inside the project directory along with a Cmakelist.txt . I think the problem is somewhere in my Cmakelist.txt because the FindSFML.cmake is just cut and paste from GitHub. I already tried the github tutorial but it was a complete mess of other problems with trying to build SFML from source. Here is what I have done so far that I can remember.


(Using Windows 10 64bit, Clion, and cmake)
1.Download latest SFML version (64-bit Windows GCC MinGW)
2.Create a new Clion project with a directory looking like this:https://i.imgur.com/K0BwyHM.png
3.Have this basic main.cpp
#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;
}
 

4. With this Cmakelist.txt

Code: [Select]
cmake_minimum_required(VERSION 3.2)
project(SFMLdemo)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SFML_ROOT "C:/SFML-2.4.1")
set(SOURCE_FILES main.cpp)
add_executable(SFMLdemo ${SOURCE_FILES})

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(SFMLdemo ${SFML_LIBRARIES})
endif()

The compiler is giving me (what I believe) can't find SFML error of:
Code: [Select]
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:5: undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:5: undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:5: undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:6: undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:7: undefined reference to `_imp___ZN2sf5Color5GreenE'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:7: undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:9: undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:12: undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:15: undefined reference to `_imp___ZN2sf6Window5closeEv'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:18: undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:18: undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:19: undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:19: undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:20: undefined reference to `_imp___ZN2sf6Window7displayEv'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:5: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
C:/Users/Jakob/ClionProjects/SFMLdemo/main.cpp:5: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
CMakeFiles\SFMLdemo.dir/objects.a(main.cpp.obj): In function `ZN2sf11CircleShapeD1Ev':
C:/SFML-2.4.1/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `_imp___ZTVN2sf11CircleShapeE'
C:/SFML-2.4.1/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `_imp___ZTVN2sf11CircleShapeE'
C:/SFML-2.4.1/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `_imp___ZN2sf5ShapeD2Ev'

My apologizes I'm sure you guys get a lot of people on this forum having trouble getting SFML started. I really didn't want to post this but I am very lost with Cmake and the only tutorial online I can find seemed vague about the cmakelist.txt part.

Thank you for your time,
-jakobnator

4
Graphics / Re: OSX build displays strange results. [C++,OSX]
« on: February 04, 2014, 05:20:53 pm »
I fixed it, make sure they are in the same path relative to the .app file.

5
Graphics / Re: OSX build displays strange results. [C++,OSX]
« on: February 04, 2014, 04:00:13 pm »
I added the Resourcepath.hpp and Resourcepath.mm from the Xcode template which can load images using the format

icon.loadFromFile(resourcePath() + "icon.png")

which doesn't work. I did some googling on the SFML forum and all the links lead to a dead thread or saying use the full directory  home/user/documents/ etc.....
which doesn't work.

6
Graphics / Re: AW: Re: OSX build displays strange results. [C++,OSX]
« on: February 04, 2014, 02:32:08 pm »

However it still isn't loading any of the images. Are directories different from windows e.g. Assets/image.png
Files get searched in the working directory. This is the directory the application is called from or some IDEs let you set it specifically.
[/quote]


I have the files in the working directory I placed it in all the folders through process of elimination and still none of them load, are OSX directories different \ instead of / perhaps?

7
Graphics / Re: OSX build displays strange results. [C++,OSX]
« on: February 04, 2014, 02:49:41 am »
Thanks, I guess window.clear() isn't necessary in windows all the time? However it still isn't loading any of the images. Are directories different from windows e.g. Assets/image.png

8
Graphics / OSX build displays strange results. [C++,OSX]
« on: February 03, 2014, 07:40:29 pm »
I have a macbook that I use for school and I am trying to get SFML to work for it but I don't consider myself an expert in xcode or OSX. I copied the code and images from my game and it builds, it doesn't load images though. However I get a strange result. (It also flashes in a siezure inducing manner)

Has anyone else ever had this problem is there something I need to do to my code in osx that doesn't need to be done in windows?

Here is my code sorry its not very well documented.

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
        using namespace sf;
        using namespace std;
        RenderWindow window;
        window.create(VideoMode(800, 600), "Red vs. Green Peppers", Style::Close);
   
        Texture tGreenpepper;
        if (tGreenpepper.loadFromFile("Assets/Greenpepper.png"))
                cout << "Loaded Greenpepper.png" << endl;
   
        Texture tRedpepper;
        if (tRedpepper.loadFromFile("Assets/Redpepper.png"))
                cout << "Loaded Redpepper.png" << endl;
   
        Texture tBoard;
        if (tBoard.loadFromFile("Assets/Board.png"))
                cout << "Loaded Board.png" << endl;
   
        Texture tMenu;
        if (tMenu.loadFromFile("Assets/Menu.png"))
                cout << "Loaded Menu.png" << endl;
   
        bool bFilled[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        bool bMenudebounce = false;
        int iTurns = 1;
   
        Sprite sPlaceholder;
        Sprite sBoard[9];
        Sprite sBackground;
        Sprite sMenu;
        sBackground.setTexture(tBoard);
        sMenu.setTexture(tMenu);
        // main loop
        while (window.isOpen())
        {
                if (iTurns % 2 == 0){
                        sPlaceholder.setTexture(tGreenpepper);
                }
                else{
                        sPlaceholder.setTexture(tRedpepper);
                }
                Event Event;
                while (window.pollEvent(Event))
                {
           
                        switch (Event.type)
                        {
                case Event::Closed:
                    window.close();
                    break;
                case Event::KeyReleased:
                    switch (Event.key.code)
                                {
                    case Keyboard::Return:
                        bMenudebounce = true;
                        break;
                    case Keyboard::Numpad1:
                        if (bFilled[0] == false && bMenudebounce == true){
                            bFilled[0] = true;
                            sBoard[0] = sPlaceholder;
                            sBoard[0].setPosition(10, 405);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad2:
                        if (bFilled[1] == false && bMenudebounce == true){
                            bFilled[1] = true;
                            sBoard[1] = sPlaceholder;
                            sBoard[1].setPosition(270, 407);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad3:
                        if (bFilled[2] == false && bMenudebounce == true){
                            bFilled[2] = true;
                            sBoard[2] = sPlaceholder;
                            sBoard[2].setPosition(548, 407);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad4:
                        if (bFilled[3] == false && bMenudebounce == true){
                            bFilled[3] = true;
                            sBoard[3] = sPlaceholder;
                            sBoard[3].setPosition(10, 205);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad5:
                        if (bFilled[4] == false && bMenudebounce == true){
                            bFilled[4] = true;
                            sBoard[4] = sPlaceholder;
                            sBoard[4].setPosition(270, 207);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad6:
                        if (bFilled[5] == false && bMenudebounce == true){
                            bFilled[5] = true;
                            sBoard[5] = sPlaceholder;
                            sBoard[5].setPosition(548, 207);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad7:
                        if (bFilled[6] == false && bMenudebounce == true){
                            bFilled[6] = true;
                            sBoard[6] = sPlaceholder;
                            sBoard[6].setPosition(10, 10);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad8:
                        if (bFilled[7] == false && bMenudebounce == true){
                            bFilled[7] = true;
                            sBoard[7] = sPlaceholder;
                            sBoard[7].setPosition(270, 10);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad9:
                        if (bFilled[8] == false && bMenudebounce == true){
                            bFilled[8] = true;
                            sBoard[8] = sPlaceholder;
                            sBoard[8].setPosition(548, 10);
                            iTurns++;
                        }
                                                break;
                    default:
                        break;
                                }
                        }
                }
                if (bMenudebounce == false){
                        window.draw(sMenu);
                }
       
                if (bMenudebounce == true){
                        window.draw(sBackground);
                        window.draw(sBoard[0]);
                        window.draw(sBoard[1]);
                        window.draw(sBoard[2]);
                        window.draw(sBoard[3]);
                        window.draw(sBoard[4]);
                        window.draw(sBoard[5]);
                        window.draw(sBoard[6]);
                        window.draw(sBoard[7]);
                        window.draw(sBoard[8]);
           
                }
        window.display();
        }
        return 0;
}
 

Pages: [1]
anything