I have installed boost by downloading and unzipping the boost_1_67_0.tar.bz2 file in the following location:
/cygdrive/c/no_admin_programs/boost_1_67_0
I have entered the following into a file test.cpp:
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " ");
}
And entered the following in the terminal:
c++ -I /cygdrive/c/no_admin_programs/boost_1_67_0 test.cpp
As a result, the following error is shown:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/cstdlib:75:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_algo.h:59,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/algorithm:62,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/core/swap.hpp:25,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/utility/swap.hpp:15,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/tuple/detail/tuple_basic.hpp:40,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/tuple/tuple.hpp:28,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/lambda/core.hpp:30,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/lambda/lambda.hpp:14,
from test.cpp:1:
/usr/include/stdlib.h:91:7: error: expected initializer before ‘__alloc_size2’
__alloc_size2(1, 2) _NOTHROW;
^~~~~~~~~~~~~
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/cstdlib:75:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_algo.h:59,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/algorithm:62,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/core/swap.hpp:25,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/utility/swap.hpp:15,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/tuple/detail/tuple_basic.hpp:40,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/tuple/tuple.hpp:28,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/lambda/core.hpp:30,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/lambda/lambda.hpp:14,
from test.cpp:1:
/usr/include/stdlib.h:144:63: error: expected initializer before ‘__alloc_size2’
void *reallocarray(void *, size_t, size_t) __result_use_check __alloc_size2(2, 3);
^~~~~~~~~~~~~
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_algo.h:59:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/algorithm:62,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/core/swap.hpp:25,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/utility/swap.hpp:15,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/tuple/detail/tuple_basic.hpp:40,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/tuple/tuple.hpp:28,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/lambda/core.hpp:30,
from /cygdrive/c/no_admin_programs/boost_1_67_0/boost/lambda/lambda.hpp:14,
from test.cpp:1:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/cstdlib:138:11: error: ‘::calloc’ has not been declared
using ::calloc;
^~~~~~
I've tried including <cstdlib> to no avail. Any assistance would be much appreciated.
if you also install the boost package alread provided on cygwin
there is no need to try to use boost_1_67_0.tar.bz2
$ cygcheck -c libboost-devel
Cygwin Package Information
Package Version Status
libboost-devel 1.66.0-1 OK
your program works fine with just
$ c++ test.cpp
$ ./test.exe
4
12 5
15 7
21 9
27
Related
Here's my code:
main.cpp
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << pow(4, 3);
cin.get();
}
So basically I try to compile with command g++ main.cpp -std=c++98
Here's what I get:
C:\Users\NullPointerException\Desktop\cpp>g++ main.cpp -std=c++98
In file included from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\postypes.h:40,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\iosfwd:40,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from main.cpp:1:
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwchar:166:11: error: '::vfwscanf' has not been declared
166 | using ::vfwscanf;
| ^~~~~~~~
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwchar:172:11: error: '::vswscanf' has not been declared
172 | using ::vswscanf;
| ^~~~~~~~
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwchar:176:11: error: '::vwscanf' has not been declared
176 | using ::vwscanf;
| ^~~~~~~
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwchar:193:11: error: '::wcstof' has not been declared
193 | using ::wcstof;
| ^~~~~~
In file included from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\locale_facets.h:39,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_ios.h:37,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:44,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,
from main.cpp:1:
c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\cwctype:89:11: error: '::iswblank' has not been declared
89 | using ::iswblank;
| ^~~~~~~~
Basically I wanted to test if c++ can deduce type for pow. But I get these errors. What's the problem and how do I fix it?
g++ version: 9.2.0
I can compile this without problems using g++ 9.3 on ubuntu. Seems you have run into a bug specific to the mingw32 variant of g++.
You might try adding include <cstdio> and perhaps also include <cstdarg> before the other includes.
I cannot test this since I'm not using mingw32.
pow is a C function, not C++, so use the alternative C header for the math library.
I am unable to compile a basic boost vector example.
I am on Windows 10, and I am using the nuwen MinGW distro version 15.0, without git included. This version contains GCC 7.10 and Boost 1.64. I have unpacked MinGw and placed it in the root of my file system and I am following the MinGW usage instruction A to run set_distro_paths.bat. Below is the code, which is failing to build on my system:
vector-fail.cpp:
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v (3);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;
std::cout << v << std::endl;
}
Makefile:
vector-fail: vector-fail.o
g++ vector-fail.o -o vector-fail
vector-fail.o: vector-fail.cpp
g++ -c vector-fail.cpp -o vector-fail.o
Output:
g++ -c vector-fail.cpp -o vector-fail.o
In file included from C:\MinGW\include/boost/numeric/ublas/vector.hpp:21:0,
from vector-fail.cpp:1:
C:\MinGW\include/boost/numeric/ublas/storage.hpp: In member function 'void
boost::numeric::ublas::unbounded_array<T, ALLOC>::serialize(Archive&, unsigned int)':
C:\MinGW\include/boost/numeric/ublas/storage.hpp:299:33: error: 'make_array' is not a member of 'boost::serialization'
ar & serialization::make_array(data_, s);
^~~~~~~~~~
C:\MinGW\include/boost/numeric/ublas/storage.hpp:299:33: note: suggested alternative: 'make_nvp'
ar & serialization::make_array(data_, s);
^~~~~~~~~~
make_nvp
C:\MinGW\include/boost/numeric/ublas/storage.hpp: In member function 'void boost::numeric::ublas::bounded_array<T, N, ALLOC>::serialize(Archive&, unsigned int)':
C:\MinGW\include/boost/numeric/ublas/storage.hpp:494:33: error: 'make_array' is not a member of 'boost::serialization'
ar & serialization::make_array(data_, s);
^~~~~~~~~~
C:\MinGW\include/boost/numeric/ublas/storage.hpp:494:33: note: suggested alternative: 'make_nvp'
ar & serialization::make_array(data_, s);
^~~~~~~~~~
make_nvp
make: *** [Makefile:5: vector-fail.o] Error 1
Unfortunately none of those errors are occurring within my code, rather they are caused by files within include files within the boost library its self. What changes could be made in application level code or the Makefile to allow the program to compile?
Yes this is an issue with the ublas headers. I ran into it before. You can workaround it by including
#include <boost/serialization/array_wrapper.hpp>
before that point though. I'd consider reporting it to the maintainers of the ublas code.
I'm trying compile this code in cmd:
#include <iostream>
#include <string>
using namespace std;
int main(){
int n = 24;
string s = to_string(n);
cout<<s;
}
I found in another qestions, that I should use this command:
g++ -std=c++11 main.cpp
but I get error:
main.cpp: In function 'int main()':
main.cpp:7:24: error: 'to_string' was not declared in this scope
string s = to_string(n);
^
I have latest g++ compiler for Windows v. 5.3.0. I used this installer for MinGW.
I tried solve in to_string is not a member of std, says g++, but this patch doesn't work.
How can I compile this code in command line in Windows?
I am using geany (code::blocks wouldnt run my programs) as a compiler to compile a simple c++ program with one class. I am on Linux Mint 17 on a Dell Vostro 1500. Compiling works fine with both .cpp files, but the header file gives this error:
gcc -Wall "Morgan.h" (in directory: /home/luke/Documents/Coding/Intro#2)
Morgan.h:5:1: error: unknown type name ‘class’
class Morgan
^
Morgan.h:6:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
{
^
Compilation failed.
This is the main.cpp :
#include <iostream>
#include "Morgan.h"
using namespace std;
int main()
{
Morgan morgObject;
morgObject.sayStuff();
return 0;
}
This is the Header file (Morgan.h):
#ifndef MORGAN_H
#define MORGAN_H
class Morgan
{
public:
Morgan();
void sayStuff();
protected:
private:
};
#endif // MORGAN_H
And this is the class (Morgan.cpp):
#include <iostream>
#include "Morgan.h"
using namespace std;
Morgan::Morgan()
{
}
void Morgan::sayStuff(){
cout << "Blah Blah Blah" << endl;
}
I really do not know what is going wrong, so any help would be appreciated. I copy and pasted the same code into a windows compiler and it worked fine, so it might just be the linux.
also when I run the main.cpp this is what shows:
"./geany_run_script.sh: 5: ./geany_run_script.sh: ./main: not found"
You don't compile .h files. Try g++ -Wall main.cpp Morgan.cpp
Your issue is that you are compiling C++ code with a C compiler (GCC). The command you are looking for is g++. The complete command that would compile your code is:
g++ -Wall -o run.me main.cpp Morgan.cpp
If a file is included (In your case the Morgan.h file, you do not need to explicitly compile it. )
can i use Symbolic C++ features in linux c++ compiler or in visual c++ 2010? and also one question sometimes in programs there is such headers code
#include <iostream>
#include "symbolicc++.h"
using namespace std;
int main(void)
{
Symbolic x("x");
cout << integrate(x+1, x); // => 1/2*x^(2)+x
Symbolic y("y");
cout << df(y, x); // => 0
cout << df(y[x], x); // => df(y[x],x)
cout << df(exp(cos(y[x])), x); // => -sin(y[x])*df(y[x],x)*e^cos(y[x])
return 0;
}
header #include "symbolicc++.h" i have tried
#include " " but it does not show me symbolicc++.h so how to do it please give me a few example
there is such error after compile
symbolic.cpp:2:25: error: symbolicc++.h: No such file or directory
symbolic.cpp: In function ‘int main()’:
symbolic.cpp:7: error: ‘Symbolic’ was not declared in this scope
symbolic.cpp:7: error: expected ‘;’ before ‘x’
symbolic.cpp:8: error: ‘x’ was not declared in this scope
symbolic.cpp:8: error: ‘integrate’ was not declared in this scope
symbolic.cpp:9: error: expected ‘;’ before ‘y’
symbolic.cpp:10: error: ‘y’ was not declared in this scope
symbolic.cpp:10: error: ‘df’ was not declared in this scope
symbolic.cpp:12: error: ‘cos’ was not declared in this scope
symbolic.cpp:12: error: ‘exp’ was not declared in this scope
Go to http://issc.uj.ac.za/symbolic/symbolic.html , download e.g. the SymbolicC++3 3.34 gzipped tar file.
Unpack that tar.gz file, and adjust your compiler/IDE to search for additional header files in the headers/subdir.
e.g. using a command line on Linux:
[nos#localhost ~]$ wget http://issc.uj.ac.za/symbolic/sources/SymbolicC++3-3.34.tar.gz
16:20:24 (109.71 KB/s) - `SymbolicC++3-3.34.tar.gz' saved [155572/155572]
[nos#localhost ~]$ mkdir symbolicc++
[nos#localhost ~]$ cd symbolicc++/ && tar -xvzf ../SymbolicC++3-3.34.tar.gz ; cd ..
[nos#localhost ~]$ gcc -Wall -I/home/nos/symbolicc++/headers -o myprogram myprogram.cpp
Some clarification to extremely helpful nos answer - you have to change gcc into g++ compiler for newer versions of GNU compilers. Here is simple GNU Makefile that compiles example/lagrange.cpp example:
PROGRAM=legendre.cpp #program to compile
LIB=../headers #localization of headers of symbolicc++ library, specifically symbolicc++.h file
run:
g++ -I$(LIB) -o main.x $(PROGRAM)
(time ./main.x)
clean: main.x
-rm main.x