SpartanJ / SOIL2

SOIL2 is a tiny C library used primarily for uploading textures into OpenGL.
MIT No Attribution
370 stars 75 forks source link

macos 10.10.2 - Missing -F flag for frameworks #6

Closed SpartanJ closed 9 years ago

SpartanJ commented 9 years ago

Original report by Johannes P. (Bitbucket: [Johannes P.](https://bitbucket.org/Johannes P.), ).


When attempting to build this repository's premake gmake file with gcc 4.8.4 and SDL 2.0.3 on mac OS 10.10.2 I noticed that the makefiles for the tests fail to compile due to the error:

#!shell

g++    -MMD -MP -DNDEBUG   -O2  -o "../../obj/macosx/release/soil2-test/test_SOIL2.o" -MF ../../obj/macosx/release/soil2-test/test_SOIL2.d -c "../../src/test/test_SOIL2.cpp"
../../src/test/test_SOIL2.cpp:12:11: fatal error: 'SDL2/SDL.h' file not found
        #include <SDL2/SDL.h>

This seems to be because the -F flag, and corresponding path to the Frameworks directory is required in both the compile, as well as the link step.

Here is a quick example illustrating the problem in detail with a super simple SDL2 program: https://bitbucket.org/snippets/JohannesMP/BA5Bo

The premake4.lua file should be modified to accommodate this.


Note: this is my first time attempting to compile SOIL2, and I don't have a lot of experience with premake, so please let me know if there is some simple step that I am missing here.

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Hi! If i remember correctly the SDL2 header file in the SDL2 Framework is not located in the SDL2 sub-folder. That seems to be the problem. But i need to make some changes in the premake4.lua file to detect if you're using xcode and the framework. I'll look into that as soon as i can.

SpartanJ commented 9 years ago

Original comment by Johannes P. (Bitbucket: [Johannes P.](https://bitbucket.org/Johannes P.), ).


Hi Martín, thanks for the fast reply!

As far as I can tell, the framework is laid out correctly, according to Apple's framework guidelines: https://developer.apple.com/library/prerelease/mac/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html - See Listing 3 under 'Additional Directories', and note that it matches the layout found in SDL2.framework:

screenshot_2015-08-03_20.11.50.png

I am Not using Xcode. This is entirely with gmake. I may be mistaken, but as far as I understand, when using a non-system framework in a program being compiled under g++ or clang you need two flags when compiling and linking:

  1. -framework (What framework)
  2. -F <PATH TO FRAMEWORK(S)> (Where to find it)

If that is done correctly than headers in the framework such as SDL.h are found automatically, or at least that seems to be what line 22 and 32 of my snippet above suggest. This is further supported when you consider the fact that without the -F flag the linking step does not work (line 28), and you don't even need the header file when linking. It simply has to do with providing the compiler with the location of the framework, and it does the rest.


To quote the man page - http://linux.die.net/man/1/g++ :

#!

-Fdir
Add the framework directory dir to the head of the list of directories to be searched for header files.
These directories are interleaved with those specified by -I options and are scanned in a left-to-right order.

So effectively, during the compilation step, you can use -I and manually provide the path to the framework's header directory, ie:

#!shell

-I /Library/Frameworks/SDL2.framework/Headers

And for that single framework would accomplish the same thing as:

#!shell

-F /Library/Frameworks

But that kind of defeats the point of using frameworks in the first place, not to mention you need to do -I /path/to/framework/header for every single framework, instead of just one -F /path/where/all/frameworks/are


TL;DR: the SDL2 framework is laid out correctly, but when compiling with g++ or clang you need to use -F /Path/To/Framework to ensure the compiler can traverse the standardized framework file structure and locate the header file.

SpartanJ commented 9 years ago

Original comment by Johannes P. (Bitbucket: [Johannes P.](https://bitbucket.org/Johannes P.), ).


A minor update:

When creating a separate premake5 project I'm able to fix this issue by manually adding the -F flag to my build and link options: https://gist.github.com/JohannesMP/9a9b5263c127103f1861#file-premake5-lua-L24-L26 (see highlighted lines) - doing so appends the correct -F ... flag to the make variables ALL_CFLAGS and ALL_LDFLAGS

However when I attempt to add that with premake4 it seems that the resulting make file fails to include the flags in All_CFLAGS as well as ALL_LDFLAGS (as can be seen when using make verbose=1). I'm not quite sure why.

I'll play around with it a bit more. I can manually get the make files to compile if I append -F /Library/Frameworks to each instance of ALL_CFLAGS and ALL_LDFLAGS in the resulting .make files

On a semi-related note, here is an issue regarding frameworks in premake that I opened on the premake repo: https://github.com/premake/premake-core/issues/196

SpartanJ commented 9 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


This should improve the tests on OS X.

Thanks for your help,

Regards