I'm newbie to c++, and I'm using mingw compiler. the last line
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
....
string url ("http://www.google.com");
curlpp::Cleanup myCleanup;
curlpp::options::Url myUrl(url);
throws the following long error while compilation
C:\Users\UserName\AppData\Local\Temp\ccpkmZ1C.o:test.cpp:(.text$_ZN6curlpp11Option
TraitISsL10CURLoption10002EED1Ev[curlpp::OptionTrait<std::basic_string<char, std
::char_traits<char>, std::allocator<char> >, (CURLoption)10002>::~OptionTrait()]
+0xb): undefined reference to `_imp___ZTVN6curlpp11OptionTraitISsL10CURLoption10
002EEE'
...
...
What's wrong here? Do I need to do something more then copying include folders from curlpp and libcurl to use curlpp?
Thank you in advance!
This is a linker error.
You need to add the libcurl libraries to the build command.
Something like:
g++ test.cpp -o test -llibcurlpp
I am not sure of the exact name of the libcurl library.
In your curlpp distribution (.tar.gz file, usually) you can find all the documentation you need. Basically, you may want to take a look at README, doc\guide.pdf and include\curlpp\ directory for class/function definitions.
If you don't have any of these, make sure you get the latest sources, as today.
Hope it helps.
Related
I am trying to switch to Windows environment from Linux, but find it a very hard path.
This time I wanted to test if I can work with boost library.
I had problems with compiling boost on windows, so I downloaded precompiled version. I unpacked everything and tested positively that I can compile the header-only librariers.
Then I copied some simple boost::asio example. I set up everything in Eclipse. Compilation went fine, but during linking I got 'undefined reference' problem to 'boost::system' internal stuff.
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
So I added '-lboost_system', as well as the path to the libraries directory, to my linking options. But this did not help.
g++ "-LC:\\Users\\jacek\\cpp\\boost_1_62_0\\lib64-msvc-14.0" -o TestAsio.exe "src\\Main.o" -lboost_system
I checked the libraries directory and found there is a bunch of files containing 'boost_system' in the name. They are:
libboost_system-vc140-mt-1_62.lib
libboost_system-vc140-mt-gd-1_62.lib
libboost_system-vc140-mt-s-1_62.lib
libboost_system-vc140-mt-sgd-1_62.lib
libboost_system-vc140-s-1_62.lib
libboost_system-vc140-sgd-1_62.lib
I did not know which I should use. I tried adding 'libboost_system-vc140-mt-1_62' to the linking options, I tried all other files, I tried renaming the files to the linux pattern 'libboost_system.a', but nothing worked.
g++ "-LC:\\Users\\jacek\\cpp\\boost_1_62_0\\lib64-msvc-14.0" -o TestAsio.exe "src\\Main.o" -llibboost_system-vc140-mt-1_62 -llibboost_system-vc140-mt-gd-1_62 -llibboost_system-vc140-mt-s-1_62 -llibboost_system-vc140-mt-sgd-1_62 -llibboost_system-vc140-s-1_62 -llibboost_system-vc140-sgd-1_62
What am I doing wrong here?
Please help...
YotKay
I solved it myself with the help of a comment from this post: boost asio example compilation error
It looks like the precompiled version of Boost is created with Visual Studion and is NOT COMPATIBLE with G++. I if I decided to install MinGW then I cannot use the precompiled version of boost, but must compile it myself using g++.
I did that.
Now I have libraries compiled with G++.
I specify the path to the boost system library like that:
c:\Users\jacek\cpp\boost_1_62_0\libraries\boost\bin.v2\libs\system\build\gcc-mingw-6.2.0\debug\link-static\
and add this option:
-lboost_system-mgw62-d-1_62
Now the problem with boost::system disappears. However, another one pops up with boost asio, but luckily the answer is here: MinGW linker error: winsock
The example works fine now on my Windows 10 laptop.
#include <boost/asio/io_service.hpp>
#include <boost/asio/steady_timer.hpp>
#include <chrono>
#include <iostream>
using namespace boost::asio;
int main()
{
io_service ioservice;
steady_timer timer{ioservice, std::chrono::seconds{3}};
timer.async_wait([](const boost::system::error_code &ec)
{ std::cout << "3 sec\n"; });
ioservice.run();
}
This might not even be a cling question, I'm a C++ newbie.
I am trying to play around with a library called QuantLib in the cling REPL.
I'm able to load the library in GCC by doing
#include "ql/quantlib.hpp"
and then compiling with -lQuantLib.
In cling I've been trying permutations of the 3 lines below:
.I "ql/quantlib.hpp"
#include "ql/quantlib.hpp"
.L QuantLib
If I run the #include first, I get a very long error, including stuff like
You are probably missing the definition of
QuantLib::AbcdAtmVolCurve::accept(QuantLib::AcyclicVisitor&) Maybe you
need to load the corresponding shared library?
But if I run
.I "ql/quantlib.hpp"
#include "ql/quantlib.hpp"
then all seems well.
.L Quantlib results in
input_line_4:1:10: fatal error: 'QuantLib' file not found
#include "QuantLib"
regardless of when it's run.
I tried the following after kfsone's comment
.L /usr/lib/libQuantLib.so
#include "ql/quantlib.hpp"
This gives a short error!
IncrementalExecutor::executeFunction: symbol '_ZN8QuantLib5ErrorC1ERKSslS2_S2_' unresolved while linking function '__cxx_global_var_init34'!
You are probably missing the definition of QuantLib::Error::Error(std::string const&, long, std::string const&, std::string const&)
Maybe you need to load the corresponding shared library?
Cling needs to know both the syntax of the structures/functions you want to use and have the binary code that executes.
For the syntax you have to add the include, for example like this:
#include "myfile.hpp"
For the binary code, you have to load the library like this:
#pragma cling load("myfile.so.9.220.0")
this will probably a dumb question for you guy's but I have no experience in C++ what so ever. I'm using an open source project osrm (which is awesome). Still to request a route, you have make an http request. To reduce the running time, I would like to build a wrapper around the code and call it using the command line. So I googled a bit and found that osrm already creates a static lib (.a file) when compiling the project. I also found a piece of code that points me in the right directions for building a wrapper. So to begin I build a simple hello world program (see below) that includes some files from that static lib. To compile I followed this tutorial.
My directory structure looks like this:
./helloWorld.cpp
./libs/libOSRM.a
And the command to compile is this:
gcc –static helloworld.cpp –L ./libs –l libOSRM.a
The code it selve:
#include "Router.h"
#include "boost/filesystem/path.hpp"
#include "ServerPaths.h"
#include "ProgramOptions.h"
#include <InternalDataFacade.h>
#include <viaroute.hpp>
#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}
the exact error I got:
fatal error: ServerPaths.h: No such file or directory #include "ServerPaths.h"
Add the -IPathToTheHeaderFiles to the compiler options. So it will find the files to be included. Replace PathToTheHeaderFiles with the path where your file ServPaths.h resides.
Edit: Add as many -I as you need for further header files.
Additionally it would be worth to read a book about C++ or/and the GCC manual1
1 Section 3.11 will help.
This is a really basic question because I am a C++ newbie. I want to use the Boost.Interprocess library, but am having trouble building it. I'm trying to follow these instructions, but it's not working for me. Here is what I have:
#define BOOST_DATE_TIME_NO_LIB
#include <boost/interprocess/shared_memory_object.hpp>
#include <iostream>
using namespace std;
int main() {
cout << "Hello, beautiful world!\n";
}
But I get this error:
boost_1_55_0\boost\date_time\gregorian_calendar.hpp(63) : fatal error C1083: Cannot open include file: 'boost/date_time/gregorian_calendar.ipp': No such file or directory
I know Boost is able to load properly, because I can get an example that uses #include <boost/lambda/lambda.hpp> to work just fine. It's just when I try to include the Boost.Interprocess library that I am having trouble. The cause is clearly because it's having trouble including the Boost.DateTime library properly, but according to the documentation (linked above) I should be able to get by without separately compiling Boost.DateTime if I define BOOST_DATE_TIME_NO_LIB, right?
What am I missing here?
You need to add it to the preprocessor
In VS go to - Project >> properties >> C/C++ >> Preprocessor in the 'Preprocessor Definitions' paste BOOST_DATE_TIME_NO_LIB.
You can download boost libraries here: https://www.boost.org/users/download/
After that, you can include them in your projects. Also, you can check this video on how to add boost libraries in eclipse IDE on Ubuntu: https://www.youtube.com/watch?v=gN8zrnWxFeI
I am learning C++, and I decided to make a little program that zip/unzip files to train me.
I downloaded libzip and zlib and linked them to my compiler (MinGW with Code::Blocks on Windows). So I tried to open my zip file with zip_open() and got an error :
undefined reference to _imp__zip_open
Here is the code:
#include <zip.h>
#include <zlib.h>
int main()
{
int error(0);
zip *foo = zip_open("foo.zip", 0, &error);
return 0;
}
I don't know where this is coming from and I would really like some help, because I don't find anything on Google (surely cause the problem is simple).
Thanks in advance!
It looks like you haven't linked to libzip. Make sure you are infact linking to it, and that the path to the lib is in your link path.
Judging by the discussion on this thread from the libzip-discuss list it looks like you are trying to link against a static version of libzip but with the preprocessor symbol ZLIB_DLL defined. You should only have ZLIB_DLL defined if linking against the dll version.