How to use png++ (C++ library) on Windows? - c++

I am trying to use this C++ library (png++) on Windows, but I unable to compile any program when I use it. Example of Code I am using to test:
#include <png++/png.hpp>
#include <png.h>
int main(){
//anything
}
When I try to compile using g++ -I path/png++ main.cpp -o main, I get
fatal error: png++/png.hpp: No such file or directory
#include <png++/png.hpp>
I understand png++ depends on libpng, I tried adding it as an I- flag, i.e. compile using
g++ -I path/png++ -I path/libpng main.cpp -o main, but it doesn't resolve the issue, png.h is found by the compiler but not png++/png.hpp.
I hope someone will be able to help.
Thanks!

Related

Getting error: fatal error: curl/curl.h: No such file or directory #include <curl/curl.h>

I'm trying to use cURL but every time I try to compile a project with it, I get the same error mentioned in the title. I am aware of the dozen or so post about similar issues. However, most of the solutions I've read so far either don't work or I can't seem to find an analog for me as I'm using mingw32 on a windows 10 OS.
I am trying to use the curl-7.76.1-win32-mingw.zip. I got it from the cURL site, and no matter where I try to stick the files, I can't get anything to compile correctly.
Someone, please explain your solution or ideas to me like I'm 5. My brain has melted.
Here is the actual error:
PS C:\Users\Me> g++ -I "C:\Program Files\Curl\curl-7.76.1-win32-mingw\include\curl" -c "D:\Personal\Projects\#####\#####\#####\#####\main.cpp" -o "D:\Personal\Projects\#####\#####\#####\#####/main"
In file included fromD:\Personal\Projects\#####\#####\#####\#####\main.cpp:4:
D:\Personal\Projects\#####\#####\#####\#####\testapi.hpp:7:10: fatal error: curl/curl.h: No such file or directory
#include <curl/curl.h>
^~~~~~~~~~~~~
compilation terminated.
[Finished in 0.6s]"
Mingw is gcc for windows. Practically everything that applies to gcc applies to mingw.
It's better to use relative paths in your Makefile and with gnu make (which is part of mingw/msys) always use '/' as path separator. If you have to use absolute path like C:\dev\projects\mylib use it this way: C:/dev/projects/mylib.
Back to your curl: curl/curl.h is in C:\path\to\curl-7.76.1-win32-mingw\include\curl\curl.h so you need to add include directory to your gcc command line that points to the right directory, which is C:\path\to\curl-7.76.1-win32-mingw\include because you use "curl/curl.h". If you don't have it (that curl) installed system wide it's also better to use "curl/curl.h" in #include path than <curl/curl.h>.
So all you have to do is add -Ipath/to/curl-7.76.1-win32-mingw/include to your compile line, like:
g++ -O2 -Ipath/to/curl-7.76.1-win32-mingw/include -c -omain.o main.cpp
It can be done automatically in Makefile:
CXX = g++
CFLAGS += -O2
INCLUDES += -Ipath/to/curl-7.76.1-win32-mingw/include
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCLUDES) $*.cpp
You write:
g++ -I "C:\Program Files\Curl\curl-7.76.1-win32-mingw\include\curl"
try better:
g++ -I "C:\Program Files\Curl\curl-7.76.1-win32-mingw\include"
as you have written in the code sample:
#include <curl/curl.h>
or conserve the -I option as it was, and change your #include to:
#include <curl.h>
I sincerely hope this will help.

Error compiling C++ source utilizing the Boost.Math library

I'm trying to use a couple of functions from the Boost Math library in some C++ code using the G++ compiler but I've been unsuccessful. This is on macOS.
I downloaded and extracted the Boost tar.gz from here and placed it into my source folder.
Within my C++ I've tried
#include "boost_1_63_0/boost/math/distributions/chi_squared.hpp" and
#include <boost_1_63_0/boost/math/distributions/chi_squared.hpp>.
The quotation version partially works but the chi_squared.hpp file includes fwd.hpp using the bracket (#include <...>) notation and that breaks my compilation with error In file included from main.cpp:9: ./boost_1_63_0/boost/math/distributions/chi_squared.hpp:12:10: fatal error: 'boost/math/distributions/fwd.hpp' file not found #include <boost/math/distributions/fwd.hpp>.
To compile I've used an assortment of commands, all unsuccessfully:
g++ -L /boost_1_63_0/boost/math/distributions main.cpp
g++ -I"/boost_1_63_0/boost/math/" main.cpp
g++ -I "/boost_1_63_0/boost/math/" main.cpp
g++ main.cpp -lboost_math
What is the correct include statement and G++ command that I need to use?
Resolved using
#include "/Users/[me]/[project_dir]/boost_1_63_0/boost/math/distributions/chi_squared.hpp"
and
g++ -I/Users/[me]/[project_dir]/boost_1_63_0/ main.cpp

gmp.h missing when trying to use boost library

I am trying to use the boost library with QT on windows. I've successfully build the library and also managed to include it in my project. However, on including gmp (#include "boost/multiprecision/gmp.hpp") and creating an object (boost::multiprecision::mpz_int myint;) I get the following error:
C:\Users\Laurenz\Documents\libraries\boost_1_66_0\include\boost\multiprecision\gmp.hpp:31: error: gmp.h: No such file or directory
And indeed, I haven't been able to find any such file in the boost directory. What did I do wrong?
Install the dependency and link to it. (See What is an undefined reference/unresolved external symbol error and how do I fix it?)
Alternatively, consider not using GMP, using cpp_int.hpp instead.
Since you already installed the GMP library, here's the last step:
Live On Coliru
#include <boost/multiprecision/gmp.hpp>
#include <iostream>
int main() {
boost::multiprecision::mpz_int i("1238192389824723487823749827349879872342834792374897923479");
std::cout << pow(i, 3) << "\n";
}
Note the -lgmp flag at the end of the compile/link command:
g++ -std=c++11 -O2 -Wall -Wextra -pedantic main.cpp -o demo -lgmp
Running it:
./demo
1898298004808110659499396020993351679788129852647955073547637871096272981567489303363372689896302906549189545322451852317205769760555889831589125591739044248515246136031239

C++ library header not found

I am OS X user and I've recently installed "cppunit" library using brew. When I try to compile "test.cpp" file using TestCase.h header the error occurs:
> test.cpp:3:10: fatal error: 'TestCase.h' file not found
> #include "TestCase.h"
I am compiling this file:
test.cpp
#include <iostream>
#include "TestCase.h"
using namespace CppUnit;
class EmptyTest : public TestCase
{
};
int main()
{
}
Using this command:
g++ -Wall -pedantic -std=c++14 test.cpp -o test.x -lcppunit
I've also tried compiling with -I giving the path to the library directory but still with the same error.
All my friends using cppunit and brew can simply include the header and the program works fine.
I would appreciate every answer.
I've solved this problem. I had issues with Xcode. Reinstall works fine.

how to fix the error: ‘::max_align_t’?

I get the error
"/usr/include/c++/5/cstddef:51:11: error: ‘::max_align_t’ has not been declared
using ::max_align_t;
^"
So I should update the libraries because I find this solution:
"A workaround until libraries get updated is to include <cstddef> or <stddef.h> before any headers from that library."
I wrote some command on the Ubuntu terminal such as:
bash $ sudo apt-get install apt-file
bash $ sudo apt-file update
bash $ apt-file search stddef.h
Then still the error exist.
Thank you
In the .cpp file where this compile error occurs you need to add
#include <cstddef>
before any of the other headers, e.g.
main.cpp (broken)
#include <cstdio>
int main()
{
using ::max_align_t;
puts("Hello World");
return 0;
}
Try to compile that:
$ g++ -std=c++11 -o test main.cpp
main.cpp: In function ‘int main()’:
main.cpp:5:10: error: ‘::max_align_t’ has not been declared
using ::max_align_t;
^
Then fix it:
main.cpp (fixed)
#include <cstddef>
#include <cstdio>
int main()
{
using ::max_align_t;
puts("Hello World");
return 0;
}
Compile and run it:
$ g++ -std=c++11 -o test main.cpp
$ ./test
Hello World
I compiled some code with GNU C++ 4.9 on CentOS, and the issue was not solved by ensuring top position #include (or by the older header name stddef.h).
Weird enough, I searched all header files of the compiler libraries for the global definition of max_aling_t as declared in the offending using declaration... and found none! Could it be in some 'internal compiled header?
So I simply commented-out the "using ::max_align_t;" line in the standard header (not proud of doing this indeed) and it solved the problem... and code is running...
if anyone can explain what is the meaning/impact of this max_align_t ?
I also commented-out the using ::max_align_t; line in /usr/include/c++/4.9/cstddef, while, code is running, but I don't know if there are any consequences by doing this...