JUCE program won't compile

Introduction

This doesn’t sound like a problem to me :smiley:

I’m always happy to help with issues related to building (even if it’s not with CMake). Let’s see what went wrong for each platform that you tried.

MinGW-64

When compiling under MinGW-w64, you are getting a lot of linker errors because you need to link against the Windows libraries that are listed in the header file of each JUCE module as mingwLibs. For instance, in juce_core.h:

Projucer parses the header file for each module:

and then adds the libraries to the linker settings:

Here is how I add these libraries to PListMerger, a very simple command line helper executable of FRUT:

MSVC with Visual Studio 2019

From https://cmake.org/cmake/help/latest/command/add_executable.html:

If WIN32 is given the property WIN32_EXECUTABLE will be set on the target created. See documentation of that target property for details.

and from https://cmake.org/cmake/help/latest/prop_tgt/WIN32_EXECUTABLE.html:

When this property is set to true the executable when linked on Windows will be created with a WinMain() entry point instead of just main().

Projucer does that by setting the proper value for the “SubSystem”:

which results in /SUBSYSTEM:CONSOLE or /SUBSYSTEM:WINDOWS being passed to the linker.
See /SUBSYSTEM (Specify Subsystem) | Microsoft Learn for more details.

g++ under Ubuntu

This is similar to MinGW-64, you need to link against the Linux libraries that are listed in the header files of each JUCE module as linuxLibs. The call to pkg-config only applies to linuxPackages.

Projucer extract both linuxLibs and linuxPackages here:

but they are not handled in the same way.

linuxLibs are directly passed to the linker:

linuxPackages are passed through pkg-config to both the compiler and the linker:

Since some of the linuxPackages depend on the linuxLibs, you ended-up with only a single error left. From https://linux.die.net/man/3/dlclose:

Link with -ldl.

Conclusion

I hope all of this will help you.

As you can see building JUCE using CMake is not straightforward. This is why I created FRUT.

Don’t hesitate to ask me any question (here or on PM) about CMake/FRUT/Projucer or anything else related to building JUCE projects.

5 Likes