External Libraries to Link exports as CMake variable

When I specify External Libraries to Link in Projucer under the Android exporter like so:

some_library_a
some_library_b

Then the generated target_link_libraries command in app/CMakeLists.txt looks like this:

target_link_libraries( ${BINARY_NAME}

    ${log}
    ${android}
    ${glesv3}
    ${egl}
    ${some_library_a}
    ${some_library_b}
    "cpufeatures"
    "oboe"
)

This is treating the library names as CMake variables (which are not defined) resulting in not linking to libsome_library_a.a and libsome_library_b.a.

I’m inclined to think that Projucer should export the External Libraries to Link without the ${} surrounding the library names. Or am I missing something?

Specifying the libraries to link as part of Extra Linker Flags (like -lsome_library_a) add those names to CMAKE_SHARED_LINKER_FLAGS which in my case doesn’t seem to work for some reason.

Any tips on how to properly link prebuilt libraries?

This looks like it’s probably a bug. I’ll get that fixed.

1 Like

Thank you, this works!
Why are you putting the library names between square brackets?

The change, for future reference:

The square brackets are just slightly safer delimiters than ".

2 Likes

This change has appeared to break linking when the user library has an ${ANDROID_ABI} in the name, the variable apparently doesn’t make it through to the link step (which is obviously needed in most cases when doing multi-arch builds).

The previous way has worked just fine for me for a long time, so I’m not sure what the cause of the original poster’s issue is… there is a find_library() earlier in Projucer-generated CMakeLists.txt for each of the user libraries, and they must be working properly to define the variable version… perhaps they just weren’t for the original poster? Maybe not specifying the library path in the extra library search paths in the Debug/Release targets?

Incidentally, it’s the square brackets which break it… works fine with double quotes.

1 Like

As @sonosaurus mentioned, the square brackets break my multi-arch builds, deleting them and using just the variable name associated with the library is perfectly fine. Yes I’m using the ${ANDROID_ABI} variable.

My case was about linking mosquitto, OpenSSL and crypto

The original CMakeLists.txt which makes an app that cannot find libmosquitto.so:

target_link_libraries( ${BINARY_NAME}

    ${log}
    ${android}
    ${glesv2}
    ${egl}
    "cpufeatures"
    "oboe"
    [[mosquitto]]
    [[ssl]]
    [[crypto]]
)

modified CMakeLists.txt which makes an app that runs fine:

target_link_libraries( ${BINARY_NAME}

    ${log}
    ${android}
    ${glesv2}
    ${egl}
    "cpufeatures"
    "oboe"
    mosquitto
    ssl
    crypto
)

Could this be fixed, @reuk ?

So, it seems the case that removing the square brackets would solve the issue, right?

I think that makes sense and I would be in favour of doing that.

It did seem so at first. I had this set up running and building an app, then decided to share my finding on the forum. Once I did that and came back to the build to try a few more times it didn’t work anymore. At this point I’m very confused and not being able to run the app without crashing on start on any android device or the android VM.

Let’s put it on hold, I’ll try to solve my issues and then will confirm if the removal of square brackets helps.

Is there a clear tutorial anywhere that would instruct me how to setup the ProJucer project, so that nothing has to be changed manually in the Android CMakeLists.txt file?

@ruurdadema maybe you could help me out with that on another thread?

1 Like