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.

Community
  • 1
  • 1
capcom
  • 3,257
  • 12
  • 40
  • 50

1 Answers1

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
Community
  • 1
  • 1
Vyktor
  • 20,559
  • 6
  • 64
  • 96
  • Would `-Iinclude` be `-Iheaders` if, say, the headers were located in a folder called headers instead of include? – capcom Oct 13 '12 at 20:11
  • @capcom yes they would, I've added a link which describes it in gcc "Manual" – Vyktor Oct 13 '12 at 20:12