cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problem when linking libcurl with Eclipse and MinGW

From: Johan Vermeire <jvme38_at_gmail.com>
Date: Sun, 1 May 2011 20:23:14 +0200

Hi,

I am trying to compile and linking on Windows
a small libcurl example with Eclipse and MinGW.

simple.c:
---------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
    res = curl_easy_perform(curl);

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}
---------------------------------------------------------------------------------------------------

Makefile:
---------------------------------------------------------------------------------------------------
#CC := mingw32-g++
CC := gcc
CFLAGS := -g -Wall -DCURL_STATICLIB
INCLUDES = -IE:/curl-7.21.6-devel-mingw32/include
LIBRARIES = -LE:/curl-7.21.6-devel-mingw32/lib

RM := rm -rf
TARGET := simple
OBJS := simple.o
SRCS := simple.c

all: $(TARGET)

$(TARGET): $(OBJS) $(SRCS)
        @echo 'Building ' $(TARGET)
        $(CC) $(LIBRARIES) -lwldap32 -lws2_32 -lcurl -o $(TARGET) $(OBJS)
        @echo 'Build Successfully'
        
%.o: %.c
        @echo 'building $@ from $<'
        $(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $<

clean:
        $(RM) $(OBJS) $(TARGET)
---------------------------------------------------------------------------------------------------

The result of the build process is:
---------------------------------------------------------------------------------------------------

**** Build of configuration Default for project libcurl_simple_1 ****

mingw32-make VERBOSE=1 all
'building simple.o from simple.c'
gcc -g -Wall -DCURL_STATICLIB -IE:/curl-7.21.6-devel-mingw32/include
-o simple.o -c simple.c
'Building ' simple
gcc -LE:/curl-7.21.6-devel-mingw32/lib -lwldap32 -lws2_32 -lcurl -o
simple simple.o
simple.o: In function `main':
E:\workspace\libcurl_simple_1/simple.c:30: undefined reference to
`curl_easy_init'
E:\workspace\libcurl_simple_1/simple.c:32: undefined reference to
`curl_easy_setopt'
E:\workspace\libcurl_simple_1/simple.c:33: undefined reference to
`curl_easy_perform'
E:\workspace\libcurl_simple_1/simple.c:36: undefined reference to
`curl_easy_cleanup'
collect2: ld returned 1 exit status
mingw32-make: *** [simple] Error 1
---------------------------------------------------------------------------------------------------

I always get the 'undefined reference' errors during the linker step.
Does anybody have a solution for this?

Hope someone can help

Johan Vermeire
Software engineer
Belgium
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-05-01