Hi all,

I have defined a new librray and want to simple include it in my program. I use #include</my path/library.h> and it works very well.
but each time that I want to run my program in a new machine I have to change "mypath" manually. is a way that the program it self can find out the path? I mean a function maybe being used or what ever.

Thanks,

Recommended Answers

All 3 Replies

The answer to your question is no, because the #include directive is run at compilation time. It's long done by the time you run your program at all, much less on another machine. To change the path in the directive, you'd have to recompile.

Usually a relative path is sufficient:

#include "library.h"

If the header resides in the same directory as the executable file, or one of the standard library directories, it should work fine. Alternatively, you can ensure that the absolute path exists on the target machine.

The answer to your question is no, because the #include directive is run at compilation time. It's long done by the time you run your program at all, much less on another machine. To change the path in the directive, you'd have to recompile.

Usually a relative path is sufficient:

#include "library.h"

If the header resides in the same directory as the executable file, or one of the standard library directories, it should work fine. Alternatively, you can ensure that the absolute path exists on the target machine.

Thanks, this "" does solve the problem. the problem was that I used <> notation rather than "", any way, it works fine now.

In legalese the <> notation is no different from the "" notation. They both have "implementation-defined" behavior. In the real world, however, the <> notation is used for headers supplied by the compiler and the "" notation is used for third-party headers.

The idea is that the <> notation will first search the standard library directories and any directories defined by one or more of the system's environment variables. The "" notation adds the current working directory and/or the directory of the executable file for your program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.