简体   繁体   中英

How do you link C packages so you can use them in your program?

I am using Netbeans with a MinGW compiler on Windows 10 . I have downloaded the sources files for the library called libjpg but I can't find anywhere on the internet specific steps on how to link C packages so you can use them.

I know in linux you can build it using...

./configure
make
make install

How do you do this with windows with the source files?

C itself doesn't have a way to do this; C was created before packages were a common thing.

Note that the ./configure , make , make install system is completely unrelated to C, except that it's often used for programs written in C.

In general, you need to tell the compiler to look in the library for include files, and you need to tell the linker to include the library in the final program. Most build systems do a lot of other things at the same time, but these are the bare essentials. The way to do this depends on the compiler - I see you're using MinGW (a port of GCC).

When you compile the program with GCC, you need to add -I (that's a capital "i" for "include") followed by the path where it should look for include files. Look around the library for a folder that has include files in it. Say it's at libjpg/include in the current directory, then you would add -Ilibjpg/include . (I assume you already know how absolute and relative paths work)

When you link your program (which might be with the same command that compiles it, depending on how you're doing it) you need to use -L - it works like -I but for library files ( .a and/or .so files). You also need to use -l (lowercase "l" for "library") to tell it to actually use the library. After -l you put the name of the library, without lib at the start and without the extension, so if it's libjpg.so then you'd use the option -ljpg .

Installing a package will put the include files and library files in the usual locations, so that you don't need to use -I or -L . You could do that yourself, if you want, even if the package doesn't actually have an installer. I'm not sure what the "usual locations" are for MinGW.

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