0

I have downloaded and setup the libjpeg package for Dev C++. I have ensured it is the most recent version. Then I have added the respective libraries in Dev C++:

Tools > Compiler > Directories I also have the compiler set to TDM-GCC 4.8.1 64-bit Release

What I have added: Bin: Dev-Cpp\bin

Libraries: Dev-Cpp\lib

C Includes: Dev-Cpp\include

C++ Includes: Dev-Cpp\include

I have also add a link in the project parameters Linker: Dev-Cpp/lib/libjpeg.a

My code:

#include <iostream>
#include <cstdlib> 
#include <cstdio> 

extern "C" {

  #include <jpeglib.h>  
  #include <jerror.h>
}

int main(void)
{ 
  struct jpeg_decompress_struct cinfo; 
  struct jpeg_error_mgr jerr; 
  cinfo.err = jpeg_std_error(& jerr); 
  jpeg_create_decompress(& cinfo); 
  return 0; 
}

I am getting the errors:

D:\FP\main.o    In function `main':
14      D:\FP\main.cpp  undefined reference to `jpeg_std_error'
15      D:\FP\main.cpp  undefined reference to `jpeg_CreateDecompress'
...

I have looked at this post which seems relevant but I don't know how to apply it to C++. In that forum I've linked to, the problem was somehow solved when a commenter told the OP to specify which compiler was used for the library. I.e. GCC for C and G++ for C++. I am getting the same errors as he did, so I think it is related, but I'm not sure how to reconfigure it.

I've looked at the post:

What is an undefined reference/unresolved external symbol error and how do I fix it?

But this does not answer my question as this is a general answer for undefined references.

Community
  • 1
  • 1
Klik
  • 1,757
  • 1
  • 21
  • 38
  • _"as this is a general answer for undefined references"_ Yes, read it – Lightness Races in Orbit Nov 09 '14 at 00:30
  • Thanks for the link, I've just finished reading it. It's very informative, but it doesn't seem to have the answer I'm looking for. There is a reference to C libs in C++ and I've already done what was suggested. One thing did seem relevant however, and it was "In gcc you'd add the files to the command line"--regarding the linking. This is similar to what I have mentioned in my question but it does not elaborate how to do it. Which is what I want to know. – Klik Nov 09 '14 at 01:11
  • @Klik how to add linker flags or objects to link should be mentioned in the documentation of your IDE. – PeterT Nov 09 '14 at 01:14
  • @PeterT That sounds like some great terms that I can google. Since I have been looking for the better part of 5 hours, could you just confirm for me that it is indeed a linking problem? Even though I have already added a linking parameter in the project options. – Klik Nov 09 '14 at 01:21
  • @Klik yes, it found the header and all the symbols, it marked `jpeg_std_error` and `jpeg_CreateDecompress` as symbols that are defined "somewhere else". During the linking stage it didn't find them anywhere though. As the answers to the linked question should make clear. – PeterT Nov 09 '14 at 01:24

1 Answers1

0

You have set up your IDE to find libraries in the correct place, but you have not set up your project to actually link with libjpeg. In your project settings, you will find a place to do so.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • My mistake, I forgot to mention my links. I have tried linking with: Dev-Cpp/lib/libjpeg.a and Dev-Cpp/lib/libjpeg.dll.a. I've tried doing each one separately and then both together. – Klik Nov 08 '14 at 23:30
  • @Klik: Remotely I'm not going to be able to see what you did wrong. You could show a bunch of screenshots of your project settings, but this is getting way out of the scope of a Q&A repository. Have you tried asking in a chatroom or on a forum? – Lightness Races in Orbit Nov 08 '14 at 23:32
  • For the past three hours I have been trying to set up libjpeg. I thought this is a forum that would be able to answer my question? Would you have a suggestion for me? – Klik Nov 08 '14 at 23:38
  • The question this is linking to does not answer my question. My question is with regards to implementing libjpeg in Dev C++. It is especially tricky since libjpeg is a C library and I'm using C++ code. In the other forum I've linked to, the problem was somehow solved when a commenter told the OP to specify which compiler was used for the library. – Klik Nov 08 '14 at 23:40
  • _"It is especially tricky since libjpeg is a C library and I'm using C++ code."_ That does not make it tricky whatsoever. – Lightness Races in Orbit Nov 09 '14 at 00:30
  • @Klik: This is not a "forum". – Lightness Races in Orbit Nov 09 '14 at 01:44