Linking returns error for custom installed libcurl library on Debian - libcurl

I am working a Debian system running Stretch and building with g++. The latest Debian libcurl package is of libcurl version 7.38.0. I am trying to implement multipart form post by following this sample; it uses curl_mime_init which was added in libcurl version 7.56.0. I custom installed the latest version of the library and I am able to initialise a curl object but the linker returns an error for curl_mime_init().
#include<iostream>
#include <curl/curl.h>
using namespace std;
int main(){
CURL *curl;
curl_mime *form = NULL;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl)
form = curl_mime_init(curl);
}
I didn't install the library in the proper /usr/local folder. The program is built with
g++ test.cpp -o test
-I/home/Documents/curl-master/include
-L/home/Documents/curl-master -lcurl
The sample says that the exact code has not been verified to work. What could be the problem?

I think perhaps it's your non-standard install location that's to blame. If I build the same library on Ubuntu (so that's g++ version(Ubuntu 7.3.0-16ubuntu3) 7.3.0) but I don't install it (so I just do configure and make) and then build the test with reference to that:
g++ test.cpp -o test -I/home/fin/Desktop/curl-7.61.0/include -L/home/fin/Desktop/curl-7.61.0/lib/.libs -lcurl
then it links fine.
I should note that I didn't pass any parameters to configure

Related

Cpp including SDL library with GCC

Im currently trying to compile a cpp program with gcc that uses SDL2 library, and im using Ubuntu 20.04 LTS. Here is my folder structure
project
-out
-SDL2
-src
-main.cpp
Excluding the library i have uploaded everything to this repo https://github.com/probottpric/libtest if it gives a better understanding.
To install SDL2, I installed source code and ran ./configure and make all. I dont want to run make install which installs it on /usr/*. I want the library to be on the local folder.
To compile program im using this command
gcc -o ./out/main ./src/main.cpp -ISDL2 -lSDL2 -lSDL2main -lm -std=c++11
But It shows library not found error. What am i doing wrong ?

Chilkat sample, linkSample.cpp program, could not be compiled

I have downloaded "Chilkat C/C++ Library Downloads for Qt, CodeBlocks, MinGW, TDM-GCC, and MinGW-w64" version of Chilkat library in order to run above ftp c++ code.
#include <stdio.h>
#include "include/CkZip.h"
#include "include/CkFtp2.h"
#include "include/CkMailMan.h"
#include "include/CkXml.h"
#include "include/CkPrivateKey.h"
#include "include/CkRsa.h"
#include "include/CkHttp.h"
#include "include/CkMime.h"
#include "include/CkMht.h"
#include "include/CkSsh.h"
#include "include/CkSFtp.h"
void DoNothing(void)
{
// Instantiate the objects...
CkZip zip;
CkMailMan mailman;
CkFtp2 ftp2;
CkXml xml;
CkPrivateKey privKey;
CkRsa rsa;
CkHttp http;
CkMime mime;
CkMht mht;
CkSsh ssh;
CkSFtp sftp;
printf("Zip version: %s\n",zip.version());
}
int main(int argc, const char* argv[])
{
DoNothing();
return 0;
}
I have read the README fille and tried to run sample C++ sample linkSample.cpp.
for that reason I have read the linkSample.sh file which places in the Chilkat for Mingw folder.
I have worked in windows and loaded mingw and the path of g++ added to the cmd.
When I directly run the .sh folder command to the cmd I have received following error!
C:\Users\emma\Desktop\chilkat-9.5.0-x86_64-8.1.0-posix-seh-rt_v6-rev0>g++ -Wl,--enable-auto-import linkSample.cpp -o"linkSample.exe" -L. -lchilkat-9.5.0 -L/c/MinGW/lib -lcrypt32 -lws2_32 -ldnsapi
C:\Users\emma\AppData\Local\Temp\cciL4ofa.o:linkSample.cpp:(.text+0x10): undefined reference to `CkZip::CkZip()'
C:\Users\emma\AppData\Local\Temp\cciL4ofa.o:linkSample.cpp:(.text+0x1d): undefined reference to `CkMailMan::CkMailMan()'
C:\Users\emma\AppData\Local\Temp\cciL4ofa.o:linkSample.cpp:(.text+0x2a): undefined reference to `CkFtp2::CkFtp2()'
Could you guide me about compileing and running sample chilkat cpp program?
Thanks
I have change the workspace to linux and Also downloaded Chilkat "C/C++ Libraries for Linux" and copy the linkSample.cpp code to inside of it and run the following code:
g++ linkSample.cpp -Llib -lchilkat-9.5.0 -o linkSample -ldl
and the bin file have been appeared without error message. BUt, when I have tried to run executable bin file the following error message appears:
./linkSample: error while loading shared libraries: libchilkat-9.5.0.so: cannot open shared object file: No such file or directory
I want to keep my workspace in windows but I have just tried to see what happend in linux, and finally it does not work properly.
Any suggestion do you have?
Thanks

Difficulty linking Boost 1.60 on OS X after installing via Homebrew

I have a fresh install of OS X 10.11.4 that I immediately installed the Xcode toolchain on, then Homebrew, then Boost 1.60. In order to test that everything had gone well, I wrote the following code on my Desktop.
#include <iostream>
#include <boost/filesystem.hpp>
int main() {
boost::filesystem::path new_directory("hello");
boost::filesystem::create_directory(new_directory);
}
I then attempted to compile it as I usually have done with the following command.
$ clang++ test.cpp -o test -lboost_system -lboost_filesystem
I received the following error.
test.cpp:3:10: fatal error: 'boost/filesystem.hpp' file not found
#include <boost/filesystem.hpp>
This is how I have always compiled projects that link Boost in the past. I'm assuming that I have probably forgotten a step along the way that allows clang to search a specific path to dynamically link the libraries. What should I change in order for this compilation command to work?
For me, boost has been compiled and installed into a subdirectory of my home directory, so you'll need to modify the paths as appropriate for your homebrew installation:
flags="-std=c++1z -I/${HOME}/local/include -L${HOME}/local/lib -lboost_filesystem -lboost_system"
c++ ${flags} -o jared jared.cpp
First get the location of boost by doing the following:
brew info boost
From the image above, you can see that my location is
/usr/local/Cellar/boost/1.66.0
Then, to compile, use the following:
c++ -I /usr/local/Cellar/boost/1.66.0 main.cpp -o boost

Linking boost::asio using terminal

I am trying to link boost::asio using terminal (I'm also using a text editor).
What I tried
I did some researches on Internet (I didn't found nothing about my distro) - I found I must install that library by executing the following command on the terminal:
sudo pacman -S libboost-all-dev
This is the output I get:
error: the following package was not found: libboost-all-dev
Final question
How can I install and link correctly boost::asio with my .cpp file?
Notes:
I'm using Archlinux
To find a package in Arch Linux, do:
sudo pacman -Ss boost
This will list packages with the string boost. Or, you can look up on the package website: https://www.archlinux.org/packages/extra/x86_64/boost/
One thing you should understand about boost is that a majority of its modules are header-only; if the linker complains about undefined references then you would have to link the required files. To link boost-asio, you would do
g++ -lboost-system <source> <exe>
How to install boost in Arch Linux
You cannot link libraries inside your *.cpp files. You should enumerate required libraries using the -l option in the g++ command line.
g++ -lboos-asio -lboost-system myfile.cpp -o myapp

How to install clang in custom location from SVN, making it recognize c++ standard library, on OS X

I try to compile and use clang from svn trunk. I basically try to follow the directions here:
svn co -q http://llvm.org/svn/llvm-project/llvm/trunk llvm
svn co -q http://llvm.org/svn/llvm-project/cfe/trunk llvm/tools/clang
svn co -q http://llvm.org/svn/llvm-project/clang-tools-extra/trunk llvm/tools/clang/tools/extra
svn co -q http://llvm.org/svn/llvm-project/compiler-rt/trunk llvm/projects/compiler-rt
mkdir llvm_build_release
cd llvm_build_release
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/usr/local -DLLVM_TARGETS_TO_BUILD=host ../llvm
make -j12
make install
Above, I configure clang to be installed in the custom location ~/usr/local since I want to be able to play with it without changing my default environment.
I then create a simple test.cpp:
#include <iostream>
int main(int argc, const char* argv[]){
std::cout << "Hello world\n";
return 0;
}
and try to compile it:
~/usr/local/bin/clang++ test.cpp -o test
but get the error message:
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
(using the system version of clang, the same compilation works fine).
If I manually enter which standard library to use, it does work
~/usr/local/bin/clang++ -std=c++11 -stdlib=libstdc++ -I/usr/include/c++/4.2.1/ -L/usr/lib test.cpp -o test
The question is: How do I configure, compile and install clang from source so that I do not have to enter these standard library settings, but instead can just enter the ordinary ~/usr/local/bin/clang++ test.cpp -o test? I have macports installed, with its version of the standard libraries and the include files, if that helps.