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

Author Topic: I have a video game files, I need help setting is up in my environment  (Read 1354 times)

0 Members and 1 Guest are viewing this topic.

MorePower

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hello,
I am trying to use the following video game files project:
https://github.com/Headturna/SFML_RPG
It's an RPG game.
I am not an expert, so what I am going to do is to show you what I have done, and the errors I got, And hopefully I get some guidance on the problems/steps I missed please? Ok here we go:

First, I downloaded SFML and configured it Visual Studio Code using this method:

In summary, i did not use the visual studio preferences menu to link the libraries as shown in the SFML help page (Learn), Instead I call the libraries in a line of code, like this:
g++ -c main.cpp -I"path..\include" -DSFML_STATIC
g++ main.o -o jojo -L"path..\lib" -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lsfml-audio-s -lsfml-network-s -lopengl32 -lfreetype -lwinmm -lgdi32 -lopenal32 -lflac -lvorbisenc -lvorbisfile -lvorbis -logg -lws2_32 -mwindows -lsfml-main
But I make sure the file c_cpp_properties.json has the path to the "include".
This method worked for the very simple example and I got that green circle. I even tried a example tetris code I found on youtube it worked.
___
The problem the RPG game:
I set visual studio code on the SFML_RPG directroy, the one containing main.cpp and ALL other files.
i try to run it in a similar way bit I get these errors:

main.o:main.cpp:(.text+0x1e): undefined reference to `Game::Game()'
main.o:main.cpp:(.text+0x2a): undefined reference to `Game::run()'
main.o:main.cpp:(.text+0x3b): undefined reference to `Game::~Game()'
main.o:main.cpp:(.text+0x4e): undefined reference to `Game::~Game()'
collect2.exe: error: ld returned 1 exit status

What's the problem?
Are my lines of code short and need to include EVERY cpp file from the SFML_RPG?
Please give me some input to be able to run this.
Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: I have a video game files, I need help setting is up in my environment
« Reply #1 on: January 29, 2023, 05:13:24 pm »
I personally recommend to use Visual Studio itself, especially when you're starting out, as you then can focus on learning SFML, instead of having to fine-tune your IDE.
In either case, I do also recommend to use CMake, e.g. with the SFML CMake Template.

As for your error, since you have multiple files, you also need to list all the other cpp files, so that they get compiled and linked together.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MorePower

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: I have a video game files, I need help setting is up in my environment
« Reply #2 on: January 29, 2023, 06:00:53 pm »
You mean I need to add all the cpp files in this list?
g++ -c main.cpp -I"path..\include" -DSFML_STATIC

So that would be like this:
g++ -c main.cpp aifollow.cpp aiption.cpp ... -I"path..\include" -DSFML_STATIC ?

_
Second thing, I wanted to make a new post about it but it seems your answer partially repond to the post I wanted to make,
I wanted to use this project: https://github.com/johnBuffer/ZombieV
And I found a 'CMakeLists.txt.' fine and did not know what to do with it,

The file containts this:

Quote
cmake_minimum_required(VERSION 3.10)
set(PROJECT_NAME ZombieV)
project(${PROJECT_NAME} VERSION 1.0.0 LANGUAGES CXX)
find_package(OpenGL)

file(GLOB source_files
   "src/*.cpp"
   "src/Blur/*.cpp"
   "src/LightEngine/*.cpp"
   "src/Props/*.cpp"
   "src/System/*.cpp"
   "src/UnitedEngine/*.cpp"
   "src/Weapons/*.cpp"
)

set(SOURCES ${source_files})
set(CMAKE_CXX_STANDARD 11)

# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED COMPONENTS audio graphics window system)

add_executable(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE "include" "lib")
target_link_libraries(${PROJECT_NAME} sfml-system sfml-window sfml-graphics sfml-audio)
if (UNIX)
   target_link_libraries(${PROJECT_NAME} pthread)
endif (UNIX)

# Copy data dir to the binary directory
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

if(MSVC)
   foreach(lib ${SFML_LIBS})
      get_target_property(lib_path ${lib} LOCATION)
      file(COPY ${lib_path} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
   endforeach()
endif(MSVC)

Tried this (cmake -S . -B build) and it did not work

This seems to be the last version to use:
https://github.com/SFML/cmake-sfml-project/blob/master/CMakeLists.txt
So i need to replace this?  "${CMAKE_SOURCE_DIR}/cmake_modules"
But In my CMAKE installation there is NO FOLDER names "cmake_modules" As far as my searchs in C:\Program Files\CMake...

Same for the other pieces of this file I am not sure what to replace and with what.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: I have a video game files, I need help setting is up in my environment
« Reply #3 on: January 29, 2023, 06:04:44 pm »
You mean I need to add all the cpp files in this list?
Yes

This seems to be the last version to use:
https://github.com/SFML/cmake-sfml-project/blob/master/CMakeLists.txt
So i need to replace this?  "${CMAKE_SOURCE_DIR}/cmake_modules"
But In my CMAKE installation there is NO FOLDER names "cmake_modules" As far as my searchs in C:\Program Files\CMake...

Same for the other pieces of this file I am not sure what to replace and with what.
Read the README file in the template repository, which should explain everything. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MorePower

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: I have a video game files, I need help setting is up in my environment
« Reply #4 on: January 29, 2023, 08:02:12 pm »
Will check the CMakeList.text method later, back to the first initial problem.
I tried running the line of code as you described and used the MIGW32-make (which is working), here is it it contains EVERY cpp file:
compile:
   g++ -c main.cpp AIComponent.cpp AIFollow.cpp AIOption.cpp AnimationComponent.cpp AttributeComponent.cpp Bird1.cpp Bow.cpp CharacterTab.cpp DefaultEditorMode.cpp EditorMode.cpp EditorState.cpp Enemy.cpp EnemyEditorMode.cpp EnemySpawnerTile.cpp EnemySystem.cpp Entity.cpp Game.cpp GameState.cpp GraphicsSettings.cpp Gui.cpp HitboxComponent.cpp Inventory.cpp Item.cpp MainMenuState.cpp MeleeWeapon.cpp MovementComponent.cpp PauseMenu.cpp Player.cpp PlayerGUI.cpp PlayerGUITabs.cpp RangedWeapon.cpp Rat.cpp RegularTile.cpp SettingsState.cpp SkillComponent.cpp State.cpp stdafx.cpp Sword.cpp Tab.cpp TextTagSystem.cpp Tile.cpp TileMap.cpp VectorMath.cpp Weapon.cpp -I"personalPath...\include" -DSFML_STATIC

link:
   g++ main.o AIComponent.o AIFollow.o AIOption.o AnimationComponent.o AttributeComponent.o Bird1.o Bow.o CharacterTab.o DefaultEditorMode.o EditorMode.o EditorState.o Enemy.o EnemyEditorMode.o EnemySpawnerTile.o EnemySystem.o Entity.o Game.o GameState.o GraphicsSettings.o Gui.o HitboxComponent.o Inventory.o Item.o MainMenuState.o MeleeWeapon.o MovementComponent.o PauseMenu.o Player.o PlayerGUI.o PlayerGUITabs.o RangedWeapon.o Rat.o RegularTile.o SettingsState.o SkillComponent.o State.o stdafx.o Sword.o Tab.o TextTagSystem.o Tile.o TileMap.o VectorMath.o Weapon.o -o jojo -L"personalPath...\lib" -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lsfml-audio-s -lsfml-network-s -lopengl32 -lfreetype -lwinmm -lgdi32 -lopenal32 -lflac -lvorbisenc -lvorbisfile -lvorbis -logg -lws2_32 -mwindows -lsfml-main


Again I am using this game (https://github.com/Headturna/SFML_RPG)
Well guess what? Got the same error (and 3 warnings)
The errors:
Quote
g++ main.o -o jojo -L"personal path...\lib" -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lsfml-audio-s
-lsfml-network-s -lopengl32 -lfreetype -lwinmm -lgdi32 -lopenal32 -lflac -lvorbisenc -lvorbisfile -lvorbis -logg -lws2_32 -mwindows -lsfml-main
main.o:main.cpp:(.text+0x1e): undefined reference to `Game::Game()'
main.o:main.cpp:(.text+0x2a): undefined reference to `Game::run()'
main.o:main.cpp:(.text+0x3b): undefined reference to `Game::~Game()'
main.o:main.cpp:(.text+0x4e): undefined reference to `Game::~Game()'
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [Makefile:7: link] Error 1

Since the make method is working, why am I not able to compile this video game?
(I tested with a simple green cercle prohect and everything worked fine, but not with this game? )


Edit: nevermind it worked
« Last Edit: January 29, 2023, 08:12:10 pm by MorePower »