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

Author Topic: Building SFML game with makefile issue  (Read 7046 times)

0 Members and 2 Guests are viewing this topic.

Dooskington

  • Newbie
  • *
  • Posts: 7
    • View Profile
Building SFML game with makefile issue
« on: September 18, 2015, 01:09:46 am »
I'm having somewhat of an issue with building my SFML project. I am on Mac OSX.

It is building and running just fine, but only if I have the lib folder under /usr/local/lib. I don't want this dependency. I want to just be able to run the program on its own, referencing the lib folder that it builds from. Here is my makefile:

CC = clang++
C_FLAGS = -Wall
INCLUDE_PATH = include/
LIB_PATH = lib/
LIBS = -lsfml-system -lsfml-graphics -lsfml-window -lsfml-audio

all: collector

collector: Main.o
        $(CC) -o collector Main.o -L$(LIB_PATH) $(LIBS)

Main.o: Main.cpp
        $(CC) -c Main.cpp -o Main.o -I$(INCLUDE_PATH)

clean:
        rm -f collector *.o
 

With this makefile, it compiles with the includes in my project folders include/ directory, and the libs in my project folders lib/ directory. However, when it comes to running, it will only run if, like I said before, I have the lib folder in /usr/local/. If it is not there, I get this error:

dyld: Library not loaded: @rpath/libsfml-system.2.3.dylib

How do I fix this? I do not want to use the Frameworks, so please don't point me to those.

Also, I understand that SFML requires some external dependencies that I have placed in Library/Frameworks. Is there any way to move those into my project directory for building as well? I just want to have all SFML files tied to my project, hands down.
« Last Edit: September 18, 2015, 01:11:39 am by Dooskington »

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Building SFML game with makefile issue
« Reply #1 on: September 18, 2015, 02:03:49 am »
On most other Unix-likes you set the rpath, though it looks like Apple changed things for OSX. Take a look at this SO answer, and see if that works.

Hiura or other OSX people may know more.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Building SFML game with makefile issue
« Reply #2 on: September 18, 2015, 11:08:51 am »
Usually people on OS X who want to embed their application's dependencies create an application bundle (.app). I let you read on that; I'm sure someone has already come up with some script for Makefile to create one if you don't want to use Xcode. (You can always get some inspiration from the Cocoa example's cmake script here: https://github.com/SFML/SFML/blob/master/examples/cocoa/CMakeLists.txt)

Anyway, to solve your issue right now you can either tell clang about your custom rpath (I don't know the proper compilation flag you need to use but I'm pretty sure there's one for that), or you can run `install_name_tool` after the compilation is over. The `-add_rpath` option should do the trick, but if it doesn't work as expected, make sure the rpath is properly configured by using something like `otool -l application | grep -i -A5 -B1 LC_RPATH` and fix it with install_name_tool's other commands.

If you want to change the location of the external libraries (FLAC, ...), you can toy with install_name_tool too. But note that *all* those issues are solved if you create an application bundle from the start.
« Last Edit: September 18, 2015, 11:10:24 am by Hiura »
SFML / OS X developer

Dooskington

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Building SFML game with makefile issue
« Reply #3 on: September 18, 2015, 03:32:07 pm »
I see...

I'm new to OSX development. I'm used to just doing g++ and getting a .exe file. I've never used CMake before, or made a .app. I'm trying to reduce my dependencies, and I hate xcode. I'll try to figure out how to bundle an .app from a makefile then.

Thank you!

chipp

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Building SFML game with makefile issue
« Reply #4 on: September 18, 2015, 05:33:11 pm »
btw, i'm new in sfml (and also in every animation through programming), so i wanna ask, can C++ use with SFML?

Dooskington

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Building SFML game with makefile issue
« Reply #5 on: September 18, 2015, 05:34:20 pm »
btw, i'm new in sfml (and also in every animation through programming), so i wanna ask, can C++ use with SFML?

Yes. SFML is a C++ library.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Building SFML game with makefile issue
« Reply #6 on: September 18, 2015, 05:36:36 pm »
@chipp: please open a new discussion if you have questions that are not directly related to this subject. Thanks.
SFML / OS X developer

Dooskington

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Building SFML game with makefile issue
« Reply #7 on: September 19, 2015, 03:06:28 am »
I got it all working great. I will post it here for further reference, if anybody runs into the same issue:
There are probably some tweaks that could be done, and it will have to be modified for another project, but for the most part, the basics are there. It will compile Main.o with SFML, then link the object files to make a binary, then construct an app bundle.

CC = clang++
C_FLAGS = -Wall
SRC_PATH = src/
TARGET_PATH = bin/
INCLUDE_PATH = include/
FRAMEWORK_PATH = frameworks/
FRAMEWORKS = -framework sfml-system -framework sfml-graphics -framework sfml-window -framework sfml-audio
TARGET = Collector
APP_NAME = Collector

all: build_app package_app

build_app: $(TARGET_PATH)Main.o
        $(CC) -o $(TARGET_PATH)$(TARGET) $(TARGET_PATH)Main.o -F$(FRAMEWORK_PATH) $(FRAMEWORKS)

$(TARGET_PATH)Main.o: $(SRC_PATH)Main.cpp
        $(CC) -c $(SRC_PATH)Main.cpp -o $(TARGET_PATH)Main.o -I$(INCLUDE_PATH)

package_app:
        mkdir -p "bin/$(APP_NAME).app/Contents/MacOS"
        mkdir -p "bin/$(APP_NAME).app/Contents/Resources"
        cp -R "frameworks/" "bin/$(APP_NAME).app/Contents/Resources"
        cp src/info.plist "bin/$(APP_NAME).app/Contents"
        cp ./bin/Collector "bin/$(APP_NAME).app/Contents/MacOS/$(APP_NAME)"
        open bin/Collector.app

clean:
        rm -f $(TARGET_PATH)$(TARGET) $(TARGET_PATH)*.o
        rm -rf bin/$(APP_NAME).app/

 

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Building SFML game with makefile issue
« Reply #8 on: September 19, 2015, 08:58:18 am »
Nice  :)

BTW if you want to make sure your app is using the right dependencies, run it in lldb and use the 'image list' command to list all deps with their path.
SFML / OS X developer