symbolic c++ in GCC or microsoft visual c++ - c++

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

Related

How to include <numbers> header file and use std::numbers

running on version 11.1.0 of gcc and g++. Every time I run this code I run into issues it says std::numbers was not declared. I tried running g++ randomCodeWhileReading.cpp -o main-std=c++20 within my terminal (im running ubuntu linux) and still no change. Here is the code in question:
#include <iostream>
#include <numbers>
int main()
{
const long double pi {0};
const long double pi2 {0};
pi = std::numbers::pi_v<long double>;
pi2 = std::numbers::pi_v<long double>;
std::cout << pi << std::endl << pi2;
}
Just wanted to see the numbers module in action nothing else. (is it even called a module or is it a header file?)
EDIT 10/6/21:
The modifying a constant variable has been fixed. However, this code still wont run on my computer. Namely, the #include <numbers> does not seem to work on my machine it throws an error even when using -std=c++20. I am running gcc and g++ version 11.1 See error below:
gcc ex2_03.cpp -o -std=c++20
ex2_03.cpp: In function ‘int main()’:
ex2_03.cpp:22:65: error: ‘std::numbers’ has not been declared
22 | const double pond_diameter {2.0 * std::sqrt(pond_area/ std::numbers::pi)}; //find diameter by finding radius & multiplying by 2
|
however I was unable to replicate using godbolt.org (similar program not the same but uses as well). Clearly, it seems that this is an issue with my machine. How would I go about fixing this?
EDIT 10/8/21:
I ran the code again using more flags and changing -std=c++20 to -std=c++2a this was what was returned:
chris#chris-Aspire-E5-576G:~/Desktop/programming/c++/Learning$ ls
ex2_02 HelloWorld randomCodeWhileReading textbookExample1
ex2_02.cpp HelloWorld.cpp randomCodeWhileReading.cpp textbookExample1.cpp
ex2_02.o HelloWorld.o randomCodeWhileReading.o textbookExample1.o
ex2_03 main textbookDebug textbookOutputNameAndAge.cpp
ex2_03.cpp outputNameAndAge textbookDebug.cpp
ex2_03.o outputNameAndAge.o textbookDebug.o
chris#chris-Aspire-E5-576G:~/Desktop/programming/c++/Learning$ g++ -g -Wall -pedantic -std=c++2a -o randomCodeWhileReading.cpp
g++: fatal error: no input files
compilation terminated.
added the ls output to show I was in the correct directory.
EDIT 10/8/21 v2:
I used the following command and did not receive an error.
g++ randomCodeWhileReading.cpp -o main -std=c++20
Now just confused where the output went. By #nate's responses I assume it was sent to main? Just wanted to see a cout using std::numbers::pi
EDIT 10/8/21 v3:
All clear nate explained program can be ran by using ./main
EDIT 10/8/21 v4:
... I repeated the earlier command and got a error:
g++ randomCodeWhileReading.cpp -o main -std=c++20
cc1plus: fatal error: randomCodeWhileReading.cpp: No such file or directory
compilation terminated.
can someone explain what went wrong this time? (I am still in the same directory). After using ls it seems that the file is no longer in the directory seems to be deleted?
EDIT 10/8/21 v5:
I think the file got deleted when I was explaining the error to a friend and the wrong ways I was running the command lol. All good :D !
You need to compile with the extra flag -std=c++20.
Moreover, there is an error in your code: pi and pi2 are declared const, hence you cannot modify them after they are initialized. Use this instead:
#include <iostream>
#include <numbers>
int main()
{
const long double pi = std::numbers::pi_v<long double>;
const long double pi2 = std::numbers::pi_v<long double>;
std::cout << pi << std::endl << pi2;
}
Please try this code and this "compile" command on your machine with your version of g++:
/*
* TEST ENVIRONMENT: MSYS2 (Windows 10)
* COMPILER:
* g++ --version
* g++.exe (Rev5, Built by MSYS2 project) 10.3.0
* BUILD COMMAND:
* g++ -g -Wall -pedantic -std=c++2a -o x x.cpp
* <= NOTE: the correct command for C++ 20 compatibility in g++ 10.x is "-std=c++2a"
* RUN COMMAND:
* ./x
* 2pi=6.28319
*/
#include <iostream>
#include <numbers>
int main()
{
auto two_pi = 2*std::numbers::pi;
std::cout << "2pi=" << two_pi << '\n';
}
If it works, great. If it's the same, try "-std=c++20" and/or "-std=gnu++20". Look here for details: https://gcc.gnu.org/projects/cxx-status.html
See also:
https://stackoverflow.com/a/67453352/421195
https://stackoverflow.com/a/67406788/421195
Definitely "Update" your post to report back what happens. Be sure to copy/paste your commands and any error messages EXACTLY.
'Hope that helps.

Compiling error LEDA 6.1

I am trying to compile the simple Hello World! program from this tutorial LEDA Tutorial, section 1.3 using LEDA 6.1 on the UNIX system of my department.
#include <LEDA/core/string.h>
#include <iostream>
using leda::string;
using std::cout;
int main ()
{
string msg = "Hello World!";
cout << msg << "\n";
}
After setting the environment variable
LEDAROOT = /usr/local/LEDA-6.1
export LEDAROOT
I try to compile the file leda1.c containing the upper code
g++ -c leda1.c -I$LEDAROOT/incl
I get some errors witch are:
In file included from /usr/local/LEDA-6.1/incl/LEDA/system/basic.h:70,
from /usr/local/LEDA-6.1/incl/LEDA/core/string.h:16,
from leda1.c:1:
/usr/local/LEDA-6.1/incl/LEDA/system/misc.h: In function ‘int leda::Max_Value(int&)’:
/usr/local/LEDA-6.1/incl/LEDA/system/misc.h:120: error: ‘INT_MAX’ was not declared in this scope
/usr/local/LEDA-6.1/incl/LEDA/system/misc.h: In function ‘int leda::Min_Value(int&)’:
/usr/local/LEDA-6.1/incl/LEDA/system/misc.h:121: error: ‘INT_MAX’ was not declared in this scope
Can anyone help me with this problem?

error: 'make_array' is not a member of 'boost::serialization

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.

Why does my c++ compiler seem to be compiling in c

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. )

Mongo C++ Driver: mongo/client/dbclient.h: No such file or directory

I am trying to install the MongoDB C++ driver on my machine. I have followed the directions here, and everything seemed to install successfully. Still, I can't seem to include the headers. Here is a simple test program:
#include <cstdlib>
#include <iostream>
#include "mongo/client/dbclient.h"
void run() {
mongo::DBClientConnection c;
c.connect("localhost");
}
int main() {
try {
run();
std::cout << "connected ok" << std::endl;
} catch(const mongo::DBException &e) {
std::cout << "caught" << e.what() << std::endl;
}
return EXIT_SUCCESS;
}
Here are the errors I get:
g++ app/tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system -o tutorial
app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory
app/tutorial.cpp: In function ‘void run()’:
app/tutorial.cpp:6: error: ‘mongo’ has not been declared
app/tutorial.cpp:6: error: expected `;' before ‘c’
app/tutorial.cpp:7: error: ‘c’ was not declared in this scope
app/tutorial.cpp: In function ‘int main()’:
app/tutorial.cpp:14: error: ISO C++ forbids declaration of ‘mongo’ with no type
app/tutorial.cpp:14: error: expected `)' before ‘::’ token
app/tutorial.cpp:14: error: expected `{' before ‘::’ token
app/tutorial.cpp:14: error: ‘::DBException’ has not been declared
app/tutorial.cpp:14: error: ‘e’ was not declared in this scope
app/tutorial.cpp:14: error: expected `;' before ‘)’ token
Any help would be greatly appreciated.
The line app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory indicates that g++ is having difficulty finding the installed headers. In the tutorial that you linked to, the box below the suggested compilation command states
You may need to use -I and -L to specify the locations of your mongo and boost headers and libraries.
I'll assume that the installation procedure placed your header files in /usr/local/include and libraries (e.g. libmongoclient.a) in /usr/local/lib. Then, try adapting the compilation command to read
g++ -I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system app/tutorial.cpp -o tutorial