Beginner Problem: Static Linking

Hi, I just started practicing Static Linking, and I tried to link a third party library into my code, but it kept bugging error: "The header file not found", so I believe there're some steps missing from my code, wish someone can help!

Here is the situation:

I use OpenGL as the target library, it contains two directories: "Include" directory which holds header files and "lib-arm64"directory which holds "libglfw3.a" and "libglfw.3.dylib". I believe .dylib is related to dynamic linking, so I am not gonna touch that and .a file is the source code I need. Therefore:

  1. In Build Phase -> Linking Binary with Library, I attach "libglfw3.a".

  2. In Build Setting -> Search Path, I include the address of header directory "Include" in "Header Search Path" and "lib-arm64" in "Library Search Path".

  3. "#include <GLFW/glfw3.h>" is the command I copied from OpenGL website template and used in my code.

The error is: " 'GLFW/glfw3.h' file not found "

If anyone has any advice, feel free to share it, I really appreciate!


  • Another question I have, non-relevant to linking, but to debugging.

Please ignore anything down the separated line, I created a new post for that question :)

C supports two syntaxes for includes:

  • To include your own header, use quotes. For example, #include "MyTypes.h".

  • To include system headers, use angle brackets. For example, #include "<stdio.h>.

Xcode’s C compiler, Clang, has separate search paths for these:

I believe you’re crossing the streams here, hence your problems.

Finally, there’s an option to support crossing the streams, namely Always Search User Paths, but it’s been deprecated and I recommend that you avoid it.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you for your reply, Eskimo! I. can understand more of how Xcode compiler work right now.

But it looks like the issue still exist.

Here were attempts I made:

  1. I tried include the header as system header, so I added the "Include" file in System Header Search Path, and included <GLFW/glfw3.h> and <glfw3.h> separately, both compiled an error.

  2. I tried include the header as my own header, so I did the same thing but put the "Include" file in Header Search Path, and included "GLFW/glfw3.h" and "glfw3.h" separately, it still generates the same error.

I did not make other changes, the linking binary with library has libglfw3.a file, library search path has "lib-arm64" which contains ".a" file in it.

Probably I am missing some steps.

The template code I downloaded from OpenGL website: https://www.glfw.org/documentation.html The package as well from their resources: https://www.glfw.org/download.html

Once again, thank you so much for your reply, if you find other portion is missing, feel free to leave another comment. I will work on my end as well to indicate where the error comes from :)

Beginner Problem: Static Linking
 
 
Q