Hi, I’m using cmake version 3.28.3, working with the tutorial on the cmake website, and got through Step 1 Exercise 3. Using that, I tried to link a library like so:
CMake Error: Cannot determine link language for target “raylib”. CMake Error: CMake can not determine linker language for target: raylib – Generating done (0.0s) CMake Generate step failed. Build files cannot be regenerated correctly. gmake: *** [Makefile:193: cmake_check_build_system] Error 1
The only difference I can think of between what the tutorial does and what I’m doing is that I’m using a file with a “.a” extension. Honestly it’s my first time coming across that extension since I’m just getting back to c++ after about a decade. Note that I can run examples, and I definitely have g++ installed, and doing the tutorial with a .cxx file worked just fine.
What am I doing wrong? Is there a name for these “.a” files I should be searching for? Is this something that the tutorial will get to eventually, or is there some dependency I’m missing? I’m on Ubuntu 24
I don’t really understand the difference between an imported target and a normal target… It sounds like an imported target is something “already built”? Honestly I’m not even really sure what a “.a” file is.
Since you’re on linux, the “.a” is simply a static library - in this case the compiled raylib.
Your intuition regarding the target types is right. Normal targets are the things that you build from source. Imported targets are a way to use precompiled stuff in the same as the things you build.
Let’s look at your situation. You probably want something like this:
Note: because this is a static library, it does not carry any information about dependencies. If you get link errors, you may have to investigate that. From the other hand it may be possible to use find_package instead if you install raylib to a prefix after building it, or you may consider bringing raylib into your build via FetchContent module.
Oooh, ok. This clarifies it. Now that I understand “.a” is a linux concept and not really some code specific concept, it all makes more sense. I think you’re right–it’s probably best to use FetchContent.