-2

I'm using the IDE CodeBlocks and would like to use an third party library called Chilkat in my code. I can make the compiler read the header, but when i try to use some method or object from the library, the code doesn't compile.

The code:

#include <iostream>
#include <CkSpider.h>

using namespace std;

int main(){
    CkSpider m;
    m.Initialize("www.chilkatsoft.com");
    cout<<"Works"<<endl;
return 0;
}

All errors are like:

..\libchilkat-9.5.0.a(ChilkatSocket.o):ChilkatSocket.cpp|| undefined reference to `__imp_WSAStartup'|
..\libchilkat-9.5.0.a(ChilkatSocket.o):ChilkatSocket.cpp|| undefined reference to `__imp_getsockopt'|
..\libchilkat-9.5.0.a(ChilkatSocket.o):ChilkatSocket.cpp|| undefined reference to `__imp_setsockopt'|

Beyond that, there is some instructions on how to link and compile the library on the library web page (https://www.chilkatsoft.com/downloads_mingw.asp#getStarted), but i don't know where or how to use these parameters:

The -Wl,--enable-auto-import options may be required when linking. Also, link with libcrypt32.a, libws2_32.a, and libdnsapi.a as shown below:

g++ -Wl,--enable-auto-import linkSample.cpp -o"linkSample.exe" -L. -lchilkat-9.5.0
    -L/MinGW/lib -lcrypt32 -lws2_32 -ldnsapi

How and where i use this parameters so i can link and compile this library on CodeBlocks?

PS: Sorry for any english mistake

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
JOgamb
  • 9
  • 2
  • Q: Did you find the appropriate CodeBlocks documentation (http://wiki.codeblocks.org/), and were you able to configure your build command(s)? Q: Do you have all the dependent libraries you need (crypt32, ws2_32, dnsapi ... and chilkat)? This tutorial might also help: https://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/ – paulsm4 Dec 14 '20 at 06:13
  • Did the documentation help? Did you successfully configure your build command? Do you have all the required dependent libraries? Were you able to build (compile, link and run) your .exe? Please update your post. – paulsm4 Dec 16 '20 at 01:56

1 Answers1

1

The problem is a link error, not a "compile" error. Your code compiles fine - the linker just can't find one of the dependent libraries.

The problem isn't "chilkat" per se. The dependencies are "WSAStartup", "getsockopt" and "setsockopt". These are in the Microsoft Winsock library. You need to include -l ws2_32 in your build command.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • All i'm doing is click on the build button of the IDE. How can i include this parameters to the build? – JOgamb Dec 14 '20 at 02:32
  • Q: How can i include this parameters to the build? A: You need to learn how to use CodeBlocks! For example: `Project->Build options->` to set the options you cited above: `g++ -Wl,--enable-auto-import linkSample.cpp -o"linkSample.exe" -L. -lchilkat-9.5.0 -L/MinGW/lib -lcrypt32 -lws2_32 -ldnsapi`. I assume you have installed g++, the "MinGW/lib" directory, and library files for crypt32, ws2_32 and dnsapi. If you haven't, read the CodeBlocks documentation: http://wiki.codeblocks.org/ – paulsm4 Dec 14 '20 at 03:10