简体   繁体   中英

Newbie question about C libraries

Starting C and developing on Windows XP... Do the libraries I include (if personal ones) have to be in a certain directory? Or will the computer's contents be indexed to find them?

Thanks

They can be in any directory and the won't be indexed. You can pass a list of "include directories" to your compiler, which will search for headers in these directories. Likewise, you can pass a list of "library directories" to your linker where .lib files will be searched for. The specifics of how to pass these parameters to your compiler or linker depend on the compiler or IDE you are using.

The short answer is that you can just place the libraries (ie DLL files I presume) in the same directory as the executable file and they will be found.

The long answer is very much longer indeed, but for now you can get away with just knowing the above!

They can be in any directory you want, the linker just needs to know where there are when the executable is created. If you're using a command line compiler, like gcc, you use an option like "-L{directory}" and "-l{library file name}" to specify where to find libraries you want to include in your compile. This can vary with each compiler, so you have to look at the manpages/help for each compiler (but this is pretty common).

Generally almost nothing about 3rd party (or personal) libraries is automatically found by C compiler toolchains.

Depending on your toolchain, you'll need to perform some configuration so the compiler will be able to locate the headers for the library, as well as some configuration for the linker to locate the libraries.

If the program is built by statically linking the libraries, you generally won't need to do anything special to locate the libraries at runtime (since they're part of the executable). If the libraries are dynamically linked, then you need to ensure that the library is in the appropriate place at runtime (which might be as simple as making sure that it's in the same directory).

Unfortunately, each compiler has it's own way of performing this configuration (which might also differ depending on whether you want to use an IDE or not), so details would depend on what specific compiler you're interested in using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM