0

I've been looking for a somewhat simple library to read an image's pixels for a school project and after looking around i stumbled upon CImg, but after trying some code i found i only get the same error. Code:

#include <iostream>
using namespace std;

#include <CImg.h>
using namespace cimg_library;

int main(){
    CImg<unsigned char> src("test.png");
    int width = src.width();
    int height = src.height();
    cout << width << "x" << height << endl;
    for (int r = 0; r < height; r++)
        for (int c = 0; c < width; c++)
            cout << "(" << r << "," << c << ") ="
                 << " R" << (int)src(c,r,0,0)
                 << " G" << (int)src(c,r,0,1)
                 << " B" << (int)src(c,r,0,2) << endl;
    return 0;
}

Which gives this error:

/usr/bin/ld: main.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
../../bmptk/Makefile.inc:1342: recipe for target 'main.exe' failed
make: *** [main.exe] Error 1

Can anyone explain to me what i'm doing wrong or what i can do to avoid this error?

Edit: added makefile

# source files in this project (main.cpp is automatically assumed)
SOURCES := 

# header files in this project
HEADERS := 

# other places to look for files for this project
SEARCH  := 

# set RELATIVE to the next higher directory 
# and defer to the Makefile.* there
RELATIVE := ..
include $(RELATIVE)/Makefile.native
A DG
  • 1
  • 1
  • 2
  • 2
    Does this answer your question? [Undefined reference to pthread\_create in Linux](https://stackoverflow.com/questions/1662909/undefined-reference-to-pthread-create-in-linux) – Nicolas Dusart Jun 16 '20 at 09:59
  • They suggest using "gcc -pthread -o term term.c" to compile your work, but i use a makefile to run my code, is there any way i can incorporate this in the makefile (sorry if this is a dumb thing to suggest im still quite new to linux) – A DG Jun 16 '20 at 10:04
  • 1
    I can't answer without seeing your makefile. I could make assumptions about frequent practice but makefiles are very open, so, you should edit your question to include your makefile. It would help people answer you. – Nicolas Dusart Jun 16 '20 at 10:09
  • That appears to include another Makefile (on the last line) which you also need to show! – Mark Setchell Jun 17 '20 at 13:27

0 Answers0