2

This is a source of tremendous anxiety. I can't seem to get it to do anything. I am thinking about just trashing this whole project. Why isn't the linker working?

I have been sitting and look at so many different links, but I don't understand how to resolve it. I know that I have the library installed correctly, but, I can't seem to get it to link. I have the libcurl.dll in System32 file. Yet, I still do not know what to do. I am going mad trying to get it to work. I don't have any files in the Project Options>Directories>Library Directories, Project Options>Directories>Include Directories, or Project Options>Directories>Resource Directories. In the Project Options>Parameters>Linker:

"../Program Files (x86)/Dev-Cpp/MinGW64/lib/libcurl.a"

So, I don't know what else to do. I have been sitting here for about week trying to figure it out on my own. I probably should have asked for help sooner x.x Maybe I am missing files for the libcurl, but I doubt it because I downloaded the whole file. I don't know if it could be my firewall, Norton, blocking it. How would I allow permissions if it is? I have no clue what the problem is. Can someone shed some light on this. I have literally looked at every solution anyone has to offer on here

My MakeFile:

# Project: Project1
# Makefile created by Dev-C++ 5.11

CPP      = g++.exe
CC       = gcc.exe
WINDRES  = windres.exe
OBJ      = Project.o
LINKOBJ  = Project.o
LIBS     = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc "../Program Files (x86)/Dev-Cpp/MinGW64/lib/libcurl.a"
INCS     = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
CXXINCS  = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++"
BIN      = Project1.exe
CXXFLAGS = $(CXXINCS) 
CFLAGS   = $(INCS) 
RM       = rm.exe -f

.PHONY: all all-before all-after clean clean-custom

all: all-before $(BIN) all-after

clean: clean-custom
    ${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
    $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

Project.o: Project.cpp
    $(CPP) -c Project.cpp -o Project.o $(CXXFLAGS)

The Source Code:

#include <curl/curl.h>
#include <iostream>

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

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

The errors that keep popping up:

g++.exe Project.o -o Project1.exe -L"C:/Program Files (x86)/Dev-
Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-
mingw32/lib" -static-libgcc "../Program Files (x86)/Dev-
Cpp/MinGW64/lib/libcurl.a"
Project.o:Project.cpp:(.text+0x16): undefined reference to `__imp_curl_easy_init'
Project.o:Project.cpp:(.text+0x41): undefined reference to `__imp_curl_easy_setopt'
Project.o:Project.cpp:(.text+0x5c): undefined reference to `__imp_curl_easy_setopt'
Project.o:Project.cpp:(.text+0x6c): undefined reference to `__imp_curl_easy_perform'
Project.o:Project.cpp:(.text+0x83): undefined reference to `__imp_curl_easy_strerror'
Project.o:Project.cpp:(.text+0xb5): undefined reference to `__imp_curl_easy_cleanup'
collect2.exe: error: ld returned 1 exit status
C:\Projects\Makefile.win:25: recipe for target 'Project1.exe' failed
mingw32-make.exe: *** [Project1.exe] Error 1
user4581301
  • 33,082
  • 7
  • 33
  • 54
RAndre
  • 31
  • 1
  • 3
  • Off topic: Note for future questions and answers: `` tags do nothing four space indentation (or ctrl+k) is the magic for code formatting. – user4581301 Jun 08 '17 at 04:45
  • On topic: your compiler command line is missing a `-l` (link the following library) in front of `"../Program Files (x86)/Dev- Cpp/MinGW64/lib/libcurl.a"` – user4581301 Jun 08 '17 at 04:47
  • You added language tags for 2 different languages: C and C++. Please only use tags for the used language which seems to be C++. – Gerhardh Jun 08 '17 at 05:40
  • [This question](https://stackoverflow.com/questions/5485081/how-do-i-solve-these-libcurl-linking-errors) seems to be a duplicate of yours and seems to indicate a mismatch in the compilation command line that you need to add `-DCURL_STATICLIB` to the preprocessor flags – Anya Shenanigans Jun 08 '17 at 08:36
  • Thank you all for the feedback, but for the most part, I have gotten it to work, I guess I didn't link the licurldll.a file. I only linked the libcurl.a file x.x what a tragedy something so simple has kept me. But, now I am experience another error. I am missing a libcrypto.dll and idk where it is. It didn't come with my libcurl package... – RAndre Jun 09 '17 at 08:44

1 Answers1

2

That may work better as

-L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -lcurl

The -L argument adds a directory to the library search path, and the -l argument specifies which library to look for.

StephenG
  • 21
  • 3
  • I guess I didn't link the liburldll.a file, that is the only think I left needed to do this, but I can't seem to get the program to run. It is now crashing I am missing a libcrypto.dll file, but the bar package didn't come with it. Idk what to do. how do I continue? – RAndre Jun 09 '17 at 08:42
  • There are binaries here (linked from the OpenSSL web site) - https://indy.fulgan.com/SSL/ - libcrypto should be in those. Just extract to the same directory as the EXE. – StephenG Jun 10 '17 at 09:25