Cannot compile using any external libraries (Codeblocks) - c++

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

Related

XCode compile: "undeclare use of cin" how do i fix it?

I've been using Xcode 10.0 on my mac and whenever I use cin, the compiler shows an error:
|6|error: use of undeclared identifier cin|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
However, cout and other c++ built-ins are working just fine...
A few days ago I have commented out some header file in gcc's header file folder for another bug. (Is there any chance to create this problem for what I've done before with the header file folder?)
You need to
#include <iostream>
to be able to use std::cin. If you want to avoid the std:: namespace prefix, add
using std::cin;
to your code as well.

C++ Codeblocks + libcurl ends up with link errors

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

C++ Boost Link error

I am working on Windows 10 and I downloaded Boost 1.60 for Visual Studio 2015.
My first code snippet looks as:
#include <boost/thread.hpp>
#include <vector>
#include <iostream>
#include <sstream>
#include <cmath>
#include <iostream>
using namespace std;
void main()
{
std::cout << "Hello World";
}
I get the error:
>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc140-mt-gd-1_60.lib'
I have provided path for boost and also libraries as shown in pics:
You need to compile the library before using it. Here's how to compile it:
In your Windows Start menu open the "Developer Command Prompt for VS2015". Then inside the opened command prompt, execute those commands:
cd C:\boost_1_60_0
bootstrap.bat
.\b2 runtime-link=shared toolset=msvc-14.0
Wait for a couple of minutes, since compilation takes a while.
Specify in your project in Linker -> General, the Additional Library Directories path as C:\boost_1_60_0\stage\lib, and in C++ -> General the Additional Include Directories path as C:\boost_1_60_0
You should now be able to compile your code without problem.

Why does OpenCV code not work in my CodeBlocks IDE?

The Background: I need to use OpenCV for various Image Processing projects. To get it to work on my system(32-bit Windows 7, CodeBlocks IDE, TDM-GCC 4.8.1) I downloaded the OpenCV 3.0 sources from the OpenCV website and built it using Cmake(the only significant thing I did in this step was disable ipp) and mingw compiler. I linked the include directory and libraries to the C::B environment.
The Problem: When I run the following sample code I get an error.
*
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgcodecs.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat img;
img = imread("lena.jpg");
imshow("Original Image", img);
waitKey();
}
*
The error log being:
||=== Build: Debug in opencv (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function ZN2cv3Mat7releaseEv':|
F:\opencvbuild\include\opencv2\core\mat.inl.hpp|655|undefined reference to__atomic_fetch_add_4'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 9 second(s)) ===|
How do I get the library to work? Any possible hack or directly accessible binary files solution will do.

First Boost program

I have tried to write my first Boost program from information on the Boost libraries site.
Here is the code:
#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) << " " );
}
It shows me this error:
1>------ Build started: Project: boost_librarys, Configuration: Debug Win32 ------
1> boost_librarys.cpp
1>LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How can this error be fixed?
The answer to a similiar question outside SO was:
Download and install the Windows SDK from here
(link in quote may not be fitting for your system)
Make sure you have the Windows SDK installed.
The link error you're getting means that your program isn't linking to the correct libraries. Since the error refers to a Microsoft system library (kernel.lib), you'll need to make sure you've got your system set up correctly. This isn't a Boost problem per se, although it may be Boost that's interested in linking with kernel.lib.
You are on Visual, there is NO reason why kernel32.lib wouln'd be around. Anyway, it should be in C:/Program Files(x86)/MS Visual Studio/VC/lib
My guess is that you mistyped something in the project's configuration. Every lib, every additional path should be separated by a ';'. If you're unsure, click on the right [...] , in the new window there should be one item by line only.