2

I have my project in a directory called junkyard. Inside junkyard, I have test.c, and a folder called include.

My code looks like this:

#include <my_global.h>
#include <mysql.h>

int main(int argc, char **argv)
{
  printf("MySQL client version: %s\n", mysql_get_client_info());
}

And the two header files are located inside the include folder (which, again, is in the root directory of the project. So the structure's necessary files are located like this:

junkyard/test.c

junkyard/include/mysql.h

junkyard/include/my_global.h

Note that I am using GCC on Windows. I am unable to compile the program, and I have tried several approaches. How do I link the header files correctly? Thanks.

8
  • 1
    You don't link the header files, linkage is 4 compilation stages later. However, adding -Iinclude to the compiler flags may solve this.
    – user529758
    Oct 13, 2012 at 20:04
  • @H2CO3 So how do I include them when compiling test.c?
    – capcom
    Oct 13, 2012 at 20:04
  • Could you show the exact compiler line?
    – Zeta
    Oct 13, 2012 at 20:04
  • 3
    @capcom And that's bad. You don't need the slash. Only gcc -Iinclude test.c
    – user529758
    Oct 13, 2012 at 20:06
  • 1
    @capcom if you're looking for an absolute path.
    – user529758
    Oct 13, 2012 at 20:11

1 Answer 1

5

First of all difference between #include syntax:

  • #include <> means to include file from "compiler directory" (which can be set by preprocessor option -I)
  • #include "" means to include file from "local directory"

If you want to include file from your project you probably should use:

#include "include/mysql.h"
#include "include/my_global.h"

If you (for some reasons) want to still use #include <> use gcc like this:

gcc -Iinclude test.c
2
  • Would -Iinclude be -Iheaders if, say, the headers were located in a folder called headers instead of include?
    – capcom
    Oct 13, 2012 at 20:11
  • @capcom yes they would, I've added a link which describes it in gcc "Manual"
    – Vyktor
    Oct 13, 2012 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.