Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

External C Headers

Name: Anonymous 2012-02-02 17:50

I'm trying (and failing) to create header files (and the respective .c files) for functions I may want to use in any project, eg: Generic.h and Generic.c for readInRange, readPositive, etc.

Let's admit I have the following file structure:
D:\MyFuncs\Generic.h
D:\MyFuncs\Generic.c
D:\MyProject\src\main.c

What do I have to do so that I can #include "Generic.h"?
I don't want to copy it to the project directory, because that would defeat the purpose of having a "functions database" for anything I might need: from simple printing or handling user input, to CRC calculations and USART serial comms for my AVR.

I'm using Code::Blocks on Windows 7, by the way.

Name: Anonymous 2012-02-02 17:57

Learn how to use the command line to add more include directories.

Name: Anonymous 2012-02-02 18:00

I use Code::Blocks because I don't want to mess with the command line - kills productivity.

Name: Anonymous 2012-02-02 18:05

D:/

[spoiler]Out.

Name: Anonymous 2012-02-02 18:06

#include "D:/MyFuncs/Generic.h"

Name: Anonymous 2012-02-02 18:10

>>5
That's horribly ugly and doesn't even work.

Name: Anonymous 2012-02-02 18:12

But I just tried it with a header in K:/ an it worked perfectly.

Name: Anonymous 2012-02-02 18:14

>>7
Is that header related to a .c file or is it just a variable declaration?

Name: Anonymous 2012-02-02 18:25

>>8
Ah, here we go. At first it did just define a macro. Now I got this to work:

"K:/Programs/test.h"

#ifndef TEST_H
#define TEST_H

#define STRING "Hello World!"

void PrintSomething();

#endif






"K:/Programs/test.c"

#include "K:/Programs/test.h"

void PrintSomething()
{
    puts(STRING);
}



test4.c somewhere else

#include "K:/Programs/test.h"

int main()
{
    PrintSomething();
   
    return 0;
}


But the trick to make it work:
Command Line
C:\>%gcc% test4.c K:/Programs/test.c -o test4

C:\>test4
Hello World!

C:\>

Name: Anonymous 2012-02-02 18:35

Again, #include "FULLPATH" is horrible and highly... unreliable.

Name: VIPPER 2012-02-02 18:36

You can also try "../highershit.c" to include shit in the higher dirs, but needless to say its very ugly and im not sure if it even works.

Name: Anonymous 2012-02-02 18:36

>>10

Well. Unless you use some macros or #include relative to your program each time, it can't be helped.

Name: Anonymous 2012-02-02 18:40

god this thread is dumb

Name: Anonymous 2012-02-02 20:03

Add the directories to your include search path. Usually you add -I or /I to the command line. If you use an IDE look under your project settings.

Don't change these.
Name: Email:
Entire Thread Thread List