Makefile which link to library in C++ - c++

Recently, I try to create an makefile as below:
all:
g++ test.cpp -o Test
It creates an runnable Test. However, If I try to link it to an library (as LibCurl to use SSL connetion):
all:
g++ test.cpp -o Test -lcurl
It goes wrong (I already installed libcurl4-openssl-dev package as standard library)!
What does I miss? Can you give any solution? Thanks!!
Edit: The error is below:
fatal error: curl.h: No such file or directory

I guess, you need fix your sources:
#include <curl/curl.h>

The header files are missing in the include search path.
You will have install the development package of libcurl.
For example, install libcurl-devel-7.19.0-11.1.x86_64.rpm for Open Suse 11.1.
To know the list of files that would be installed by the rpm, download the rpm, type the following command in the downloaded dir.
rpm -qlp <rpmname>
As per the example above, the command would be
rpm -qlp libcurl-devel-7.19.0-11.1.x86_64.rpm
This will list the files along with the path in which it would be installed to.
In our example, the result would look like..
/usr/include/curl /usr/include/curl/curl.h /usr/include/curl/curlbuild.h
/usr/include/curl/curlrules.h
/usr/include/curl/curlver.h and so on...
and
Install the development libcurl package for the version of linux you use and include #include <curl/curl.h> in your code.
Refer http://curl.haxx.se/download.html to download the right one

Related

Can't build C++ project with XLNT library

I am trying to build a sample project using the XLNT-Library under Windows 8 using MinGW g++.
The code is the sample code found in the github Documentation:
#include <xlnt/xlnt.hpp>
int main()
{
xlnt::workbook wb;
xlnt::worksheet ws = wb.active_sheet();
ws.cell("A1").value(5);
ws.cell("B2").value("string data");
ws.cell("C3").formula("=RAND()");
ws.merge_cells("C3:C4");
ws.freeze_panes("B2");
wb.save("example.xlsx");
return 0;
}
I downloaded the library as a zip file, extracted it and copied the folder [xlnt-master-root]\include\xlnt into the folder where my main.cpp resides and then tried to compile it with this command:
g++ -std=c++14 -lxlnt -Ixlnt/include .\excelTest.cpp -o excelTest.exe
But this results in the following error:
c:/users/s/documents/myprogramms/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:
cannot find -lxlnt
I also tried copying the [xlnt-master] folder to the main.cpp location and tried to compile it again with the same result.
I can program in C++ but I have not worked with libraries before.
Can you please give me a hint how to use and compile the project with the library correctly?
FYI: I also tried building the library with with cmake as found here.
Although cmake was a success, make -j8 won't do anything because no Makefile is created in the build directory.
Maybe I went wrong here?
Thanks for your help...
using the lasted visual studio 2017,you can build the xlnt library automatic.
you can download the library below:
https://1drv.ms/f/s!AvyYANq3dYDem1g9MtINWWw7CyTH

Cygwin won't compile any c++ files

When I try to compile my Fibonacci.cpp file I get this from the compiler:
$ g++ Fibonacci.cpp
C:/cygwin/lib/gcc/i686-pc-cygwin/4.9.3/cc1plus.exe: error while loading shared libraries: cygcloog-isl-4.dll: cannot open shared object file: No such file or directory
I've downloaded the gcc-g++: GNU Compiler Collection (C++) library and it's not working. Am I missing another library?
You need to install the libcloog-isl4 package when you run the setup.exe. You are missing that file in your C:/cygwin64/bin directory. I had the same problem and I was also missing cygisl-10.dll and I had to install libisl10 package.
See this cannot compile anything with gcc on cygwin32; missing cygisl-10.dll.
Unfortunately I'm getting a different error now that I solved that, so I'm not guaranteeing a fix.

error while loading shared libraries: libgsl.so.0: cannot open shared object file: No such file or directory

I use gsl.
After I compiled my .cpp file and run it, I faced with below error:
error while loading shared libraries: libgsl.so.0: cannot open shared object file: No such file or directory
I found same as this problem in:
https://groups.google.com/forum/#!topic/cortex_var/6vluX7pP0Sk
&
Linux error while loading shared libraries: cannot open shared object file: No such file or directory
&
http://www.gnu.org/software/gsl/manual/html_node/Shared-Libraries.html
And I have done as in the above links wrote but the error is still remained.
Can anyone help me?
To make it work do the following steps
Start Borne Shell
$LD_LIBRARY_PATH= path to your gsl lib folder inside the gsl installation folder
$export LD_LIBRARY_PATH
now run your executable
It should work fine.
First, you need to locate the file (libgsl.so.0). You can do this, for example, by using the find command:
sudo find / -name "libgsl.so.0"
Let us assume, the file is located in /usr/local/lib.
(If the file has not been found, install the corresponding package or download the source, build it and install it.)
Now, you have two options:
(1) Quick & Dirty:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
This adds the path of the library to an environment variable. The disadvantage of this option is, that it is only valid for the current session. It will not work for other users. It will not work once you log off and on again.
(2) Permanent:
Review your /etc/ld.so.conf. If /usr/local/lib is not listed there, add it. Now, run ldconfig to detect the shared object file and add it to some system-wide index.
I got the same error with Krita on Arch Linux. I made a symlink with
ln /usr/lib/libgsl.so /usr/lib/libgsl.so.0
and that fixed it.
In my experience, fastStructure depends on gsl 1.6 but not the latest version.
wget http://gnu.mirror.vexxhost.com/gsl/gsl-1.6.tar.gz
tar -zxvf gsl-1.6.tar.gz
cd gsl-1.16
./configure
make
sudo make install
Add these lines to your .bashrc file on your home directory.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export CFLAGS="-I/usr/local/include"
export LDFLAGS="-L/usr/local/lib"
then, run source ~/.bashrc to set these environment variables.
It works fine when I change the version from the latest to the 1.6.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/shg047/software/gsl/lib/
such as: to-mr: error while loading shared libraries: libgsl.so.19: cannot open shared object file: No such file or directory
Have you tried updating your library? The program I was trying to run simply needed a newer version of gsl (I had 1.9.5 while it needed 2.0.0 or newer).
If you are on arch you can run:
yaourt gsl
and select the appropriate one.
You can use gsl-config --libs in you makefile or in the command line when you link the gsl library. Just type gsl-config you can find the options it offers to you. Choose the options you need, you will find compile and link process much easier than before. As a result, when I type gsl-config --libs in my terminal, I get -L/usr/local/lib -lgsl -lgslcblas -lm. Although it is very simple, first you should know where you gsl is installed. You can add the directory to the PATH environment variable or use the absolute path to execute gsl-config .
I needed libgsl.so.19:
/snap/inkscape/current/bin/inkscape: error while loading shared libraries: libgsl.so.19: cannot open shared object file: No such file or directory
I solved it with:
Installing Anaconda
searched for libgsl.so.19 and found it in ~/anaconda3/lib
run LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/anaconda3/lib (best add it to ~/.basrc)

Libusb and how to use its packages in Ubuntu

I have installed libusb by using the following command. I am not sure if it was right or not and the command was
sudo apt-get install libusb-dev
Once I have installed (and I am not sure if it has installed or not because I am a novice user of Ubuntu), I want to know how would I use the library, because I write some sample code which uses <libusb.h>, but when I compile that C++ file using
g++ test_libusb.cpp
that throws the following error,
test_libusb.cpp:2:20: fatal error: libusb.h: No such file or directory compilation terminated.
I am clueless what to do. I can't find any source on the Internet to get to the bottom of this...
I want to know two things here:
How do I add the libusb library in C/C++ so I can use <libusb.h>?
What would some sample code be? Only a few lines to see if libusb is working...
Try including it like so:
#include <libusb-1.0/libusb.h>
and then compile it like so:
g++ main.cpp -o main -lusb-1.0
Have a look at http://packages.debian.org/wheezy/i386/libusb-dev/filelist: The file you want to include is usb.h. Also, you'll have to tell the compiler where it can find the compiled library functions: Add -lusb to the compiler command line to make it load libusb.so.
Actually at least in Debian 7.4 (wheezy), and probably in Ubuntu also, there are two distinct libusb packages: libusb-dev (0.1.12-20+nmu1) and libusb-1.0-0-dev (1.0.11-1). Confusingly, they can both be installed concurrently and provide header files in different locations:
$ dpkg -L libusb-dev|grep /usr/include
/usr/include
/usr/include/usb.h
$ dpkg -L libusb-1.0-0-dev|grep /usr/include
/usr/include
/usr/include/libusb-1.0
/usr/include/libusb-1.0/libusb.h
Try #include <usb.h>. The "lib" is part of the Linux naming convention, i.e. library "foo" has header foo.h and is called libfoo-dev in the Debian package structure, and linked as -lfoo, and the compiled library files are called libfoo.a and libfoo.so.

Building a subset of boost libraries

I'm trying to build only a subset of boost libraries. For example, I have this code:
test.cpp:
#include <boost/thread.hpp>
int main (){
return 0;
}
I then do
./bcp --scan test.cpp ~/dev/boost_compact/
So the dependencies files are copied to ~/dev/boost_compact/boost.
Then, following this answer, I copy all files at the root of a regular boost and also the tools directory and run
./bootstrap
./bjam
./bjam install
This does copy all the headers to a destination directory, but it does not build/copy the libraries. This same set of actions does work in the full boost. What am I doing wrong?
Solved the problem. The reason the libraries were not being copied was that I was using the wrong boost directory, that is
./bcp --scan --boost=<path to boost build directory> test.cpp ~/dev/boost_compact/
when I should be using
./bcp --scan --boost=<path to boost source directory> test.cpp ~/dev/boost_compact/
If now you run
./bootstrap
./bjam
./bjam install
The libraries will be build.
Maybe a permission issue?
or
Perhaps try explicitly setting the libdir?
bjam --libdir=path/to/lib install