How to Install/Use libcurl with C++ on Windows/Eclipse CDT - c++

Can someone please explain how to use libcurl with C++ on Windows with Eclipse CDT/Code::Blocks or a similar IDE?
I'm very new to C++ but I know my way around Java very well.
I'm using MinGW but I keep getting this error:
C:\Core\src>g++ -I"C:\curl\include\curl" -L"C:\curl\lib64" -lcurldll core.cpp -o
core.exe
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xc81): undefined
reference to `_imp__curl_easy_init'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xca7): undefined
reference to `_imp__curl_easy_setopt'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xcc4): undefined
reference to `_imp__curl_easy_setopt'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xcd1): undefined
reference to `_imp__curl_easy_perform'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xce1): undefined
reference to `_imp__curl_easy_cleanup
What I've Tried:
If I give the wrong library path/name it will tell me that it can not find the library. So clearly it FOUND the libcurldll.a/libcurl.a files but it isn't linking with them properly.
I've tried putting the actual libcurl.dll file from the bin into every source folder possible in my project.
I've tried going to C/C++ General > Paths and Symbols then added "curl" and "curldll" to libraries and "C:\curl\lib64" to the library search path.
I've tried manually adding the -lcurl, -lcurldll, -DCURL_STATICLIB, -L"C:\curl\lib64" options to the MinGW Linker tool.
This has been stumping me for days. Please help.

Related

C++ build error using librealsense in ubuntu

I installed librealsense from the source. It was installed and build successfully.
When I tried to run the sample project (rs-hello-realsense) I have found the build error.
/usr/local/include/librealsense2/hpp/rs_types.hpp:90: undefined reference to `rs2_get_error_message'
/usr/local/include/librealsense2/hpp/rs_types.hpp:92: undefined reference to `rs2_get_failed_function'
/usr/local/include/librealsense2/hpp/rs_types.hpp:92: undefined reference to `rs2_get_failed_function'
Same kind of error from a different type of build.
CMakeFiles/rs-hello-realsense.dir/rs-hello-realsense.cpp.o: In function `rs2::error::error(rs2_error*)':
rs-hello-realsense.cpp:(.text._ZN3rs25errorC2EP9rs2_error[_ZN3rs25errorC5EP9rs2_error]+0x2e): undefined reference to `rs2_get_error_message'
rs-hello-realsense.cpp:(.text._ZN3rs25errorC2EP9rs2_error[_ZN3rs25errorC5EP9rs2_error]+0x73): undefined reference to `rs2_get_failed_function'
Finally, get it. Need to add a couple of lines in CMakeList.txt.
Which linked the libraries in the project.
find_package(realsense2 2.29.0)
target_link_libraries(rs-hello-realsense ${DEPENDENCIES} ${realsense2_LIBRARY})
OR
target_link_libraries(${PROJECT_NAME} ${realsense2_LIBRARY})
Other than all other properties of CMake File will be same

RcppGSL Windows installation trouble

I'm trying to install RcppGSL as presented in
Linking GSL library to RcppGSL on Windows machine
after copping the library as presented in the link above to C:/local323
and moving all the files in x64 up one directory into into LIB_GSL/lib as presented in the link. I used the following code.
library(Rcpp)
Sys.setenv("LIB_GSL" = "C:/local323") # this is where the library is located
Sys.setenv("PKG_LIBS"="-L(LIB_GSL)/lib -lgsl -lgslcblas")
install.packages("RcppGSL")
I added the line
Sys.setenv("PKG_LIBS"="-L(LIB_GSL)/lib -lgsl -lgslcblas")
after getting the following error(and I still got the same error) after doing some research and thought there might be a linking problem(just guessing).
The error I received was
RcppExports.o:RcppExports.cpp:(.text+0x916): undefined reference to `gsl_matrix_alloc'
RcppExports.o:RcppExports.cpp:(.text+0x945): undefined reference to `gsl_matrix_set'
RcppExports.o:RcppExports.cpp:(.text+0x993): undefined reference to `gsl_vector_calloc'
fastLm.o:fastLm.cpp:(.text+0x122): undefined reference to `gsl_vector_calloc'
fastLm.o:fastLm.cpp:(.text+0x131): undefined reference to `gsl_matrix_alloc'
fastLm.o:fastLm.cpp:(.text+0x142): undefined reference to `gsl_multifit_linear_alloc'
fastLm.o:fastLm.cpp:(.text+0x16d): undefined reference to `gsl_multifit_linear'
fastLm.o:fastLm.cpp:(.text+0x175): undefined reference to `gsl_multifit_linear_free'
fastLm.o:fastLm.cpp:(.text+0x24f): undefined reference to `gsl_matrix_diagonal'
setErrorHandler.o:setErrorHandler.cpp:(.text+0x104): undefined reference to `gsl_set_error_handler_off'
setErrorHandler.o:setErrorHandler.cpp:(.text+0x133): undefined reference to `gsl_set_error_handler'
any help is greatly appreciated!
Very best,
Steve
I would try this on the command-line, ie in cmd.exe -- not from R.
That way you should see the compilation and linking steps which may help when something go south.
"It builds at CRAN ..." so with the right files in the right location, and the proper env var set it should for you too.
Well I do not know why the following worked but I'm able to use RcppGSL
I followed the procedure from the link I posted exactly. Then instead of using
install.packages("RcppGSL")
I downloaded the zip file from CRAN and installed the package via the R GUI with the option to install from a zip. These should be identical I know, but using install.packages("RcppGSL").
Also
Sys.setenv("LIB_GSL" = "C:/local323")
is required anytime I try to compile an Rcpp file that uses the library.
I'm not sure why, but I can use the library at least.
Dirk thank you for your help. I will go over the tutorial on R-extensions to see if I can figure out what is going on.

How to link mysql in dev c++?

I just downloaded http://dev.mysql.com/downloads/mirror.php?id=414392 and set include/bin/lib folders to my compiler(tdm-gcc 4.8.1) in dev c++.
I can use functions from mysql.h (#include )
But i cant compile program.
bcoz:
undefined reference to `mysql_init'
undefined reference to `mysql_select_db'
what i have to do?
You've got the '-L' arguments including the lib directories, but you don't appear to have a '-l' argument linking the actual library. I think what you want to add is '-lmysqlclient' or something similar. Please see the following page for more information:
http://dev.mysql.com/doc/refman/5.0/en/c-api-building-clients.html

Boost undefined reference during compiling

I am getting a compile error trying to compile a simple tester program from the documentation.
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xa6): undefined reference to `_imp___ZN5boost6thread4joinEv'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xb4): undefined reference to `_imp___ZN5boost6threadD1Ev'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xcf): undefined reference to `_imp___ZN5boost6threadD1Ev'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp: (.text$_ZN5boost11this_thread18interruptible_waitEy[boost::this_thread::interruptible_wait( unsigned long long)]+0x4a): undefined reference to `_imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp: (.text$_ZN5boost6threadC1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thre ad_move_tIS4_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)]+0x23): undefined reference to `_imp___ZN5boost6thread12start_threadEv'
collect2: ld returned 1 exit status
I am using mingw 4.5 and g++ 4.5.2 on windows. Boost version v1.4.8.
I hope someone can help me solve this problem.
Thanks.
It looks like you aren't linking to the boost libraries.
Boost doesn't come with windows since it isn't a standard library. You've got to download the headers and libraries, then include the headers in your project and link to the libraries at compile time. Since you're using g++, this means adding a -l line to your compile command. The -l line must be used with each specific library you want to use also, you can't just specify the boost directory.
This page will help you get started on Windows and this page will help you get started on *nix platforms.
Once you've compiled boost, then in your example, you should compile your program with
g++ -o tester.exe -Lpath/to/boost/libraries/ -lboost_thread tester.c
Make sure you've got all your libraries linked properly.
Try putting this line first if your thread library is statically defined
#define BOOST_THREAD_USE_LIB
Also, check out this thread.

Libusb undefined reference to

I'm trying to set up libusb API on my OS. I downloaded libusb api on libusb.org. I followed the standard installation procedure:
cd into directory
./configure
make
make check //without errors
make install
Then I launched Eclipse C/C++ and copied some code from the tutorial found on the internet. But when trying to build it I got following output:
main.cpp:(.text+0x19): undefined reference to `libusb_init'
main.cpp:(.text+0x76): undefined reference to `libusb_set_debug'
main.cpp:(.text+0x8a): undefined reference to `libusb_get_device_list'
main.cpp:(.text+0x136): undefined reference to `libusb_free_device_list'
main.cpp:(.text+0x142): undefined reference to `libusb_exit'
/tmp/ccOWJGwe.o: In function `printdev(libusb_device*)':
main.cpp:(.text+0x162): undefined reference to `libusb_get_device_descriptor'
main.cpp:(.text+0x28a): undefined reference to `libusb_get_config_descriptor'
main.cpp:(.text+0x4d4): undefined reference to `libusb_free_config_descriptor'
collect2: ld returned 1 exit status
I have libusb.so in /lib and also I have usb.h in /usr/local/include and the link for the .so and libusb.a in /usr/local/lib.
Also the #include inside the code is correct.
I know that problem is in linker but I, kind of, cannot make it work :)
I'm using Fedora 15 operating system and gcc 4.6.0 20110603 (Red Hat 4.6.0-10) version compiler.
So what could I do to resolve these undefined references? Thanks very much for help :)
I did face the same problem. But I was able to solve it by adding '-lusb-1.0' to the linker.
e.g : g++ myfile.cpp -lusb-1.0
you have to set the library linker flag for compilation in the linker,
you can get a full list in the console by executing
pkg-config --list-all
These are the libraries which you have installed on your system and you have to link against the ones you want to use.
so in your example it is libusb so you do
pkg-config --libs libusb
there should be the output
-lusb
or
-lusb-1.0
This gives you the flag you have to pass to the linker. e.g.
g++ myfile.cpp -lusb[-1.0]
Then you edit the configuration of the project and search for the linkerflags, there should be a textfield for that somewhere in the buildoptions. i'm not quite shure where to find it but googling for it suggested:
Project -> Properties -> C/C++
Build -> Miscellaneous -> flags
After you found it, just add the linker flag in the textfield and you should be fine.
EDIT
since my answer is the accepted one, I also added the other flag that seems to work for a lot of people.
What is your linker command line? You need to have -lusb in the linking command; just having the header included won't work.
I don't use Eclipse C/C++ but I am pretty sure the reason is the same that I faced some while ago when setting up a C project in Netbeans.
It's not enough to have the #include in your code and the library at the right location - you also have to tell Eclipse where to look for them and how to use them. This turorial shows you how to set it up in Eclipse.