C++ Codeblocks + libcurl ends up with link errors - c++

Hi I am a C++ beginner and I wanted to learn about http requests...
I picked cURL because I have experience using it before with php.
I downloaded this version from cURL website into C:\libs
Win64 x86_64 7zip 7.51.0 binary SSL SSH Viktor Szakáts 1.81 MB
This is what I've done so far on Codeblocks:
Under Global compiler settings/Search directories/Compiler, I added this path:
C:\libs\curl-7.51.0-win64-mingw\include\curl
Under Global compiler settings/Search directories/Linker, I added this path:
C:\libs\curl-7.51.0-win64-mingw\lib
Under Global compiler settings/Linker settings, I added this paths:
C:\libs\curl-7.51.0-win64-mingw\lib\libcurl.a
C:\libs\curl-7.51.0-win64-mingw\lib\libcurldll.a
-Under Global compiler settings/compiler settings, this box is checked from before:
Have g++ follow the C++11 standard... (no idea if this matters or not...)
Also, because I was desperate I copied the contents of C:\libs\curl-7.51.0-win64-mingw to C:\Program Files (x86)\CodeBlocks\MinGW, this step makes no sense to me, but I found it online so I tried...
Now I am running this code:
#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include <curl.h>
#include <easy.h>
using namespace std;
int main(){
CURL* curl = curl_easy_init();
if(!curl){
cout << "error" << endl;
}else{
cout << "good job!" << endl;
curl_easy_cleanup(curl);
}
};
I am getting this errors:
undefined reference to `_imp__curl_easy_init'
undefined reference to `_imp__curl_easy_cleanup'
error: ld returned 1 exit status
Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s))
For some reason, including include curl/curl.h does not work, only way it works is including curl.h, same for easy.h
Any advice appreciated!
Thanks in advance!

You're linking with a static libcurl (on Windows) without having -DCURL_STATICLIB added to your CFLAGS when you build your application.
That is, you must define CURL_STATICLIB before the curl headers are included.
Described in the curl FAQ item Link errors when building libcurl on Windows

Related

Cannot compile using any external libraries (Codeblocks)

I cannot compile any code using external libraries on Code::Blocks.
I tried using the boost lambda example:
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
I have a global environment variable set up for the library:
https://imgur.com/a/maiRC
...and I think I set up the build options right.
https://imgur.com/a/BP0Xk
But my build can't detect the header file:
||=== Build: Debug in boost test (compiler: GNU GCC Compiler) ===|
C:\Documents and Settings\Charlotte\My Documents\wxTest\boost test\boo.cpp|1|fatal error: boost/lambda/lambda.hpp: No such file or directory|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Unfortunately the boost include path in your first image is cut off. But it looks like
C:\Boost\include\boost-1_62\boost
Right?
That’s most likely incorrect. If you include the lambda header like you did (which is also the usual way to include a boost Header)
#include <boost/lambda/lambda.hpp>
then there needs to exist a file called
C:\Boost\include\boost-1_62\boost\boost\lambda\lambda.hpp
That does not fit the normal Boost directory layout. There is one boost too many in there. Try setting your your global environment Boost path to:
C:\Boost\include\boost-1_62

Unable to execute program using C++ IDE Codeblock GNU GCC compiler

Good evening all and thank you for any help you can provide,
I have started off on my journey of trying to learn C++ and am struggling to execute any code that I have written. I have tried using both versions 13.12 and 16.01 of Codeblock and have also tried building multiple files. Same error message appears with all. Here is the sample code I first attempted with:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello\tI am your computer talking." << endl;
return 0;
}
Here is the error message that appears when I try to build:
File Line Message
===Build: Debug in SayHello (compiler: GNU GCC Compiler) ===
1d cannot find -1pthread
=== Build failed: 1 error(s), 0 warnings(s) (0 minute (s), 0 .. second(s)) ===
Could anyone advise on a resolution? I have read conflicting solutions, such as somewhere in my computer a file is missing (1pthread?). Again, really grateful for any advice and virtual cake will follow my saviour. Thank you!
Miles

Trouble linking/compiling Libcurl in Eclipse IDE C++ Project

Hi I am having trouble configuring an Eclipse C++ (32bit) project to use libcurl. I am using MinGW. I am on a 64bit windows OS. I have done the following so far:
Add "libcurl.lib" to the project's Libraries
Add the path of libcurl.lib to the Library Paths
Add the path to the curl header files to the Includes path
In source, I included "curl/curl.h"
However, I am seeing the following message:
Info: Internal Builder is used for build
g++ "-LC:\\projectsrc\\Network\\curl-7.34.0-win32\\lib" "-LC:\\projectsrc\\Network\\curl-7.34.0-win32\\dlls" "-LC:\\projectsrc\\Network\\curl-7.34.0-win32\\bin" -o TestLibCurl.exe "src\\TestLibCurl.o" "-lC:\\projectsrc\\Network\\curl-7.34.0-win32\\lib\\libcurl.lib"
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lC:\projectsrc\Network\curl-7.34.0-win32\lib\libcurl.lib
collect2.exe: error: ld returned 1 exit status
Below is the sample source
#include <stdio.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
int main()
{
cout << "test" <<< endl;
return 0;
}
Below is a screenshot of where I added the include path and the library file:
For your reference, I have uploaded my sample C++ eclipse project to dropbox here:
https://www.dropbox.com/s/2jowlkz6qypqe9g/TestingLibCurl.zip
The project file includes main.cpp, the libcurl.lib file, the libcurl header files, and the eclipse project setting files (.cproject, .project, .settings)
Oddly, I am able to get this to work in CodeBlocks IDE, using the same MinGW and using the same computer (Windows 64 bit). Do I need to add linker/options/flags when using Eclipse IDE?

Error with Poppler implementation with C++

I'm currently working on project which uses the poppler library. As It stands I have the following:
In the following folder (C:\Users\ ...\Anotation Extraction) I have all the files associated with a Codeblocks C++ project (including the main.cpp) as well as the current version of poppler and its associated documents in a folder called "poppler-0.22.2".
I also have a test pdf in this folder.
(System: Windows 7, 64 bit, Codeblocks using MinGW)
In my main.cpp file I have the following:
#include <iostream>
#include "poppler-0.22.2/cpp/poppler-document.h"
using namespace std;
int main()
{
const string dir = "C:\\Users\\...\\test.pdf";
poppler::document* doc;
doc = poppler::document::load_from_file(dir);
delete doc;
cout << dir << endl;
return 0;
}
However, when I try to build this code, the following errors pop up and I have absolutely no idea why.
obj\Debug\main.o||In function `main':|
C:\Users...\Anotation Extraction\main.cpp|11|undefined reference to `imp__ZN7poppler8document14load_from_fileERKSsS2_S2_'|
C:\Users...\Anotation Extraction\main.cpp|12|undefined reference to `imp__ZN7poppler8documentD1Ev'|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 1 seconds) ===|
Any help you guys could provide would be much appreciated.

Suspending system using c++ program

I am trying to suspend my system using a c++ program using SetSuspendState method but I am facing issue during linking.
I am using g++-4 (GCC) 4.3.4 20090804 (release) 1 compiler on Windows 7 OS (64bit).
The code I have written is
#include <iostream>
#include "windows.h"
#include "powrprof.h"
using namespace std;
int main() {
cout << SetSuspendState(false, true, false);
return 0;
}
Following is the error I am facing:
/cygdrive/c/Users/Vikas/AppData/Local/Temp/ccFpLgPi.o:suspend.cpp:(.text+0xa4):
undefined reference to
`_SetSuspendState#12' collect2: ld
returned 1 exit status
Kindly help me in resolving this issue.
Thanks in advance ...
I believe dlltool can be used to create import libraries from DLLs for use with GCC under Cygwin. The DLL exporting the functions pwrprof.dll should be located in your Windows system directory somewhere.
As msdn says you need to link PowrProf.lib.