0

This isn't my code, I am not a programmer but I did not expect simply compiling a provided source code would be so difficult.

Here it is, taken from Joel Yliluoma's page about "arbitrary-palette positional dithering algorithm", it was written in 2011.

This was my troubleshooting process, using MinGW:

  • The code didn't seem to make sense at all, so I realized it was written in an earlier version of C++, and added -std=c++98.
  • It couldn't find gd.h, I downloaded that from libgd's website, and directed to its directory using -I.
  • A bunch of gd related commands got a "undefined reference to" treatment. I tried to direct the compiler to gd.h/gd.c directory again using -l and followed by -lgd. And this is where I got stuck, as
  • The compiler insisted on not being able to find -lgd. I tried with different versions of libgd (especially older ones, before 2011) and sometimes it'd find what it's looking for, but then skip over them as they are incompatible.

I've also tried to compile it with another program called Dev-C++ but to no avail. Dev-C++ also gave back a "linker error". I can only assume that I messed up linking the header or library somehow, but I do not know what those terms mean frankly and just wanted a working program so I can get back to my imagery stuff. Maybe I downloaded the wrong gd.h, or I'm missing a required thing. Any help would be greatly appreciated.

Here's my current final MinGW input:

g++ -std=c++98 -Ipath\to\libgd code.cpp -Lpath\to\libgd -lgd -o executable.exe

I can assure you that path\to\libgd contains gd.h (and a bunch of other gd related stuff) and either one of these depending on which version of libgd I found: libgd.lib, libgd.dll.a, lidgb.def, libgd.rc, libgd.so.

I'm using Windows 7 64-bit.

gometz
  • 1
  • 1
  • Writing out the actual error messages would help a lot. Also, what system are you on? – pingul Mar 03 '17 at 14:23
  • Oh sorry I forgot to add, I'm using Windows 7 64-bit. Here's the error I'm currently stuck on: e:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgd collect2.exe: error: ld returned 1 exit status – gometz Mar 03 '17 at 14:27
  • To fix this yourself, you'll have to learn a bit about how *compilation* (uses `.h` header files and `.c` source files) and *linking* (uses `.o`/`.obj` object files and `.a`/`.so`/`.lib` libraries) work and what their differences are. In short: if you're getting undefined reference errors, it means you don't have a required library. See this [FAQ](http://stackoverflow.com/q/12573816/1782465). – Angew is no longer proud of SO Mar 03 '17 at 14:28
  • In short: you'll either need to build the `gd` library and link to it, or include its source `gd.c` in your `g++` line and forget about `-l`/`-L`. – Angew is no longer proud of SO Mar 03 '17 at 14:29
  • May I ask why -I and -L don't work in this case? – gometz Mar 03 '17 at 14:33
  • @gometz `-L` specifies the path to libraries. `-l` specifies a library to link (searched in the paths specified by `-L`). You've mentioned `gd.c` in your question: that's a source file, not a library. It would have to be compiled (into an object file) and that object file put (or linked) into a library. So *either* get a library and use `-l`+`-L`, *or* add `gd.c` to your `g++` line and not use `-l`+`-L`. – Angew is no longer proud of SO Mar 03 '17 at 14:40
  • That is really confusing, but thank you. At least now I know what I'm supposed to do. – gometz Mar 03 '17 at 14:44

0 Answers0