Search code examples
macosgccframeworksg++working-directory

OSX How to compile a framework using GCC/G++ sitting in a current working directory or subdirectory C/C++


Hopefully this is an ok thing to do. But since I figured it out a while ago with much struggle and haven't yet seen it on stack overflow I figured I'd both post the question and answer.

This question/solution is for OSX users to compile a framework using GCC or G++ without needing to have the framework in the following path on their system

/System/Library/Frameworks/

Solution

  • This code will compile a framework from the listed directory in the question. (Answered before) How to compile a C program that uses a Framework without using Xcode

    gcc ...  -framework frameworkName a.c b.c ... -o out
    

    This code will compile a framework from a custom directory. (Not Answered before as far as I've seen). Example of the following dir/file.

    /alt/path/to/framework/frameworkName.framework
    

    .

    FLAGS+="-F /alt/path/to/framework/ -framework frameworkName rpath /alt/path/to/framework/"
    gcc ...  $FLAGS a.c b.c ... -o out
    

    This would be an example of a subdirectory of the working directory. I know ./ is usually the convention, but I cant remember if that worked for me or not here.

    FLAGS+="-F $(PWD)/alt/path/to/framework/ -framework frameworkName rpath $(PWD)/alt/path/to/framework/"
    gcc ...  $FLAGS a.c b.c ... -o out 
    

    This is a combination of the /System/Library/Frameworks/ path, and the path $(PWD)/alt/path/to/framework/ in the same compilation.

    FLAGS+="-F $(PWD)/alt/path/to/framework/ -framework frameworkName2 rpath $(PWD)/alt/path/to/framework/"
    gcc ...  -framework frameworkName1 $FLAGS a.c b.c ... -o out
    

    If someone does locate this answer/question on stack overflow I will promptly delete my 'question'. The goal of this was to make portability of frameworks for people other than myself. How? Because if the framework is in a working directory, it can easily be moved around with the files/folder itself. It's obviously not a common thing people are trying, but maybe it'll make someones day.