Custom CFLAGS in projucer

Hi everybody,

I am trying to integrate ffmpeg into a juce project. For FFmpeg I need to write a C-wrapper, because it won’t link with the C++ name mangeling (also not with extern “C”).
So I have a c file which needs to get an additional include path. But the compiler flags in the projucer are only put into the “Other C++ flags” in XCode, the “Other C-Flags” remains empty. So after each save of the projucer I have to add the CFlags manually.

Could we either have an extra C-Flags field or the C++Flags could go into both fields, at least the -I flags?
Or is there a method I am not aware of?

Thanks for your thoughts

That seems odd to me. In a personal project, I use JUCE and ffmpeg a lot and I don’t need to write a c wrapper. In my C++/JUCE file, I simply include the ffmpeg headers like this:

extern "C" {                                                                    
    #include "libavformat/avformat.h"                                               
    #include "libavformat/avio.h"                                                   
    #include "libavfilter/avfilter.h"                                               
    #include "libavfilter/buffersink.h"                                             
    #include "libavfilter/buffersrc.h"                                              
    #include "libavutil/common.h"                                                   
    #include "libavutil/opt.h"                                                      

You could use the Extra compiler flags field in the Projucer and then specify the include paths like you would on the command line to the compiler:

Yes, that’s exactly what I did, it compiles well, but the linker doesn’t find the symbols, it says “No symbols for the architecture x86_64”…
Now I put all ffmpeg calls and includes in a .c file and all works well. Just that the Extra Compiler flags are not used when compiling the C file. They are only used when cpp files are compiled. That’s why I need to copy the -I…/ffmpeg/include in XCode into the “Other C-flags” field…

Which OS are you on. My code snippet works fine on both linux and OS X. Are you linking to the static or to the dynamic libavcodec? Are you sure you are compiling ffmpeg for x86_64?

Here are my settings:

…which results in these XCode settings:

As it works with no other changes when I link the C-file I think it shouldn’t be related, should it?
I tried first using shared because of licensing, but when it did not work I configured ffmpeg to build both and didn’t specify anything, so IIRC the default is still shared.

I’m on OSX 10.10.5 running xcode 7.2.1 and made sure ffmpeg was also compiled using CC not gcc.
My configure for ffmpeg:

./configure --prefix=../build/darwin/ --enable-shared

Thanks for your time…

For OS X you can add C flags by using the Xcode flags field in each configuration in projucer, just add OTHER_CFLAGS=-I…/ffmpeg/include

Hi Anthony, thanks for the tip. But which field in projucer do you mean with “XCode flags field”?
As I wrote before, the Extra compiler flags are only set into XCodes “Other C++ Flags”, the “Other C-Flags” stays empty.
Or do I have to modify an exporter file?

If you click on the configuration (i.e. debug, release, etc.) of an Xcode exporter in the projucer there is a field called “Custom Xcode flags” this allows you to set any xcode flags of a project, if you ever need to know what the flag name is in Xcode view your build settings and goto Editor >> Show Setting Names (if it says “Show Setting Titles” you don’t need to change anything).

Hope that helps.

1 Like

Ah ok, I looked only on the general page where the settings for all configurations are. And even then I had to look three times, I would never have found it myself. Thanks a million!

Really strange. I just made a project from scratch again and it works without any problems. This is how I configured ffmpeg:

./configure --disable-gpl --disable-static --enable-shared

I have a thought, eventually it has something to do with deployment targets and such. I usually set in Projucer/XCode 10.7 and C++11… maybe I need to configure ffmpeg the same…
I do this, since XCode keeps compiling for 10.11 on my 10.10, so I would not be able to run my own code…
For today my brains and my laptops batteries are too low…