-1

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?

sphchow
  • 145
  • 1
  • 11
  • C is not the same as C++. Which are you asking about? – elixenide Nov 10 '15 at 03:02
  • C doesn't have a way to do this. It was invented before packages. `./configure` is *totally unrelated* to C. For a personal project it's usually sufficient to use `-L`, `-l` and `-I` to tell the compiler/linker where to find the package's library/include files. – user253751 Nov 10 '15 at 03:08
  • @immibis can you give me an example? Do I just provide the folder location? Also what's the conventional directory to place new packages? – sphchow Nov 10 '15 at 03:12
  • 1
    Build tutorial: http://stackoverflow.com/questions/12652178/compiling-libjpeg –  Nov 10 '15 at 03:20

1 Answers1

1

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.

user253751
  • 57,427
  • 7
  • 48
  • 90
  • Thanks for the more detailed info. This helps a lot. I also used @ZirconiumHacker which was helpful on how to use compile the package **[HERE](http://stackoverflow.com/questions/12652178/compiling-libjpeg)** Do you know if generally IDE's provide a GUI option to link libraries? I'm not using command line to compile my project. – sphchow Nov 10 '15 at 06:31