GEN variables not identified - PARI library C - gcc

I have recently installed PARI library on ubuntu 16.04. The set of examples provided with the source are running correctly but , if I use "gun", "ghalf", etc., gcc compilation fails with error :
error: ‘gun’ undeclared (first use in this function)
I am new to this library and know very little about it. Can anybody please help me in fixing this error.
This is the code that I am trying to compile :
#include<stdio.h>
#include <pari/pari.h>
int main(void)
{
GEN i,j,k;
pari_init(500000,2);
i=gun;
j=stoi(3);
k=gadd(i,j);
printf("1+3=%s\n",GENtostr(k));
return 0;
}

It looks like you're using code intended for a very old version of PARI. Modern versions use gen_1 rather than gun for the constant 1. With this change,
gcc -o test-pari test-pari.c -lpari && ./test-pari
yields
1+3=4
as desired. Alternatively (not recommended!), if you're trying to port a lot of old code, you could add
#define PARI_OLD_NAMES
before
#include <pari/pari.h>
and the code with work with gun.

Related

GDB Failed to find frame when using BOOST library with GCC 4.9 on OSX

My problem is when debugging from Eclipse a program that uses Boost (even pure header) then the GDB debugger is unable to locate frame base for the function being trace into.
Please note that except this, the program works like a charm in debug and release mode. The problem is only for debugging and inspecting source code refering to Boost.
Please not also that the problem only affects OSX Yosemit.
The issue is that I can't see the value of the local variables. Below is the message I have in the "(x)= Variables" window of Eclipse :
Failed to execute MI command:
-data-evaluate-expression result
Error message from debugger back end:
Could not find the frame base for "main()".
The code is as simple as :
#include <boost/regex.hpp>
#include <iostream>
int main() {
int result = 1;
boost::regex reExpression("[a-z]+");
std::cout << "!!!Hello World !!!" << std::endl;
result ++;
cout << " Result = " << result << "\n";
return result;
}
The program is compiled using the command :
g++ -v -o -g bin/Essai-MACOS-Debug src/Essai.cpp -I/opt/local/include /opt/local/lib/libboost_regex-mt.a
If you remove the reference to Boost.Regex then everything is ok. I can inspect the value of the local variable result.
More interesting: I built a library with a single function relying on Boost, and call that function from main(). It happens that can inspect the code in main() and have the value of main's local variable but when I came inside the library's function, the one now referring to boost then again I can't see the local variables of that function.
So it seems that as soon as a source file is referring to Boost, GDB get confused.
I have installed GCC 4.9, GDB 7.7 and Boost 1.57 using MacPort on OSX Yosemit.
I've compile Boost from source with MacPort in order to use GCC instead of GCC using the command :
sudo port install -ns boost config.compiler=macport-gcc-4.9
I also tried with a version of Boost I compiled myself and I did have the same issue.
Does anyone knows about this problem ?
EDIT:
I've compiled and installed the last GDB version from sources (7.9) and have the same issue described here than with the 7.7.1 provided by MacPorts.

Getting Started with C development and GTK+

I'm really a Python developer exclusively, but I'm making my first foray into C programming now, and I'm having a lot of trouble getting started. I can't seem to get the hang of compilation and including libraries. At this point, I'm just identifying the libraries that I need and trying to compile them with a basic "hello, world" app just to make sure that I have my environment setup to do the actual programming.
This is a DBus backend application that will use GIO to connect to DBus.
#include <stdlib.h>
#include <gio/gio.h>
int
main (int argc, char *argv[])
{
printf("hello, world");
return 0;
}
Then, I try to compile:
~$ gcc main.c
main.c:2:21: fatal error: gio/gio.h: No such file or directory
#include <gio/gio.h>
I believe that I've installed the correct packages as indicated here, and gio.h exists at /usr/include/glib-2.0/gio/gio.h.
I found a command online to add a search directory to gcc, but that resulted in other errors:
~$ gcc -I /usr/include/glib-2.0/ main.c
In file included from /usr/include/glib-2.0/glib/galloca.h:34:0,
from /usr/include/glib-2.0/glib.h:32,
from /usr/include/glib-2.0/gobject/gbinding.h:30,
from /usr/include/glib-2.0/glib-object.h:25,
from /usr/include/glib-2.0/gio/gioenums.h:30,
from /usr/include/glib-2.0/gio/giotypes.h:30,
from /usr/include/glib-2.0/gio/gio.h:28,
from main.c:2:
/usr/include/glib-2.0/glib/gtypes.h:34:24: fatal error: glibconfig.h: No such file or directory
#include <glibconfig.h>
^
compilation terminated.
There has to be some relatively simple method for being able to set some options/variables (makefile?) to automatically include the necessary headers. I'm also going to use Eclipse-CDT or Anjuta as an IDE and would appreciate help to fix the import path (or whatever it's called in C).
Any help is greatly appreciated.
Use pkg-config (and make). See exactly this answer to a very similar question. See also this and that answers. Don't forget -Wall -g flags to gcc ..
You don't need an IDE to compile your code (the IDE will just run some gcc commands, so better know how to use them yourself).

cygwin g++ std::stoi "error: ‘stoi’ is not a member of ‘std

I have:
-cygwin 1.7.25 on windows 7/32bit
-g++ --version --> g++ (GCC) 4.8.2
-libstdc++.a --> gcc-g++-4.8.2-1
Tried to make a c++
Hello World:
#include <string>
int main()
{
std::string s = "123";
int i = std::stoi(s);
}
compiling gives:
$ g++ -std=c++11 main.cpp
main.cpp: In function ‘int main()’:
main.cpp:6:10: error: ‘stoi’ is not a member of ‘std’
int i = std::stoi(s);
I searched for hours but I still could not find a solution. What's the issue here?
That's a bug, possibly an incomplete port of some library code to cygwin (it's a cplusplus11 feature) - some stuff has to be changed after all. Make sure to report it.
The solution is easy of course: #include <cstdlib> strtol(s.c_str(),0,10);
www.cplusplus.com/.../strtol
A similar mingw bug is mentioned also here
std::stoi doesn't exist in g++ 4.6.1 on MinGW
I have the same problem yesterday. "error: 'stoi' is not a member of 'std'."
First, I made sure c++11 was enabled. Then, I updated the g++ compiler to the newest version. After that, this error disappeared.
The compiler is not being taken seriously. On windows your best bet is to probably use visual studio, as it is always kept up to date . The bug here is that the macro defs are wrong to begin with. The problem starts from iomanip.h and iosbase . So they would have to changed all of there code. There are user made patches for this but I would not trust them at all, as they may contain even more bugs then the original copies. But it's up to you , I just stick with visual studio express edition.
stoi works correct only on mingw64 for me.
If you use Codeblocks, don't forget to check if your projects compiler is set to mingw64.
Well, I am working with -std=c++98, not -std=c++11 but I solved it with the following:
int i = std::atoi(input.c_str());
atoi() is waiting for c type null-terminated string, c_str() makes it null-terminated char*. To use atoi I also() added the following library:
#include <cstdlib>
my system is:
Ubuntu 22.04.1 LTS

Difference between gcc and g++ when running c++ program with boost library?

I wrote a c++ program using boost library in Xcode. Here is my code. It is very simple.
#include <iostream>
#include </usr/local/include/boost/math/special_functions/beta.hpp>
using namespace std;
using namespace boost::math;
int main (int argc, char * const argv[])
{
double a = 100.0;
double b = 100000.0;
double x = 0.3;
double result = beta(a, b, x);
cout << result << endl;
return 0;
}
But when I tried to build it in the Xcode, there popped up a lot of errors related to the library linking stuff. I noticed that the compiler that Xcode was using was "System Default: gcc 4.2". And all other options are gcc or LLVM gcc (I have no idea what this is).
I later tried to compile the file simply using terminal. Weird thing happened. If I compile it with g++, without any extra flags, the compilation completed successfully and the the program could be ran normally; but if I compile it with gcc, there are pages of errors.
So, to sum it up, while using g++, everything is OK; while using gcc, everything is not OK. Since the Xcode is using gcc, the program could not be compiled using Xcode.
(And I kind of need to use the Xcode because this is just a test program, I actually have a much bigger project to handle and I depend on the debugger of Xcode.)
So my question is, WHAT THE HELL is the difference between gcc and g++? Or how can I change the compiler of Xcode to g++?
gcc is a C compiler.
g++ is a C++ compiler.
You're trying to compile C++, ergo, you need to use a c++ compiler.
Googling "Using XCode for c++" brings up lots of results, but this one seemed fairly straightforward and had pictures:
https://www.cs.drexel.edu/~mcs171/Wi07/extras/xCode_Instructions/index.html
The gcc command compiles C files (although you can use -libstdc++) to link C++ files as well but I don't recommend it.
The g++ command works for C++ files which is why it worked in your case.
For XCode you have to change the compiler from GCC to G++ for it to successfully work.

Gmp apparently not working under MinGW

I struggled during the whole afternoon with GMP and Mingw, and after a HUGE number of tries I made to install it. Actually, what I did is: installing a fresh brand new copy of MinGW (32 bit, standard latest version, downloaded from sourceforge), selecting the msys component during installation, and then using msys to install GMP from sources.
1) I downloaded sources from the home page of the gmplib official website (just the standard source release, link in the upper part of the home page).
2) I extracted it into some location reachable from msys.
3) I did the "./configure" step
4) Then the "make" step
5) Then "make install"
6) Then "make check".
No problems, it looked like it was just working. I tried to compile this under gcc:
#include <stdio.h>
#include <gmp.h>
int main(int argc, char *argv[])
{
mpz_t a, b; /* working numbers */
return 0;
}
It compiled without any error. But then, when I try to add:
mpz_init(a);
right under the declaration of a, gcc prints out:
C:\Users\MATTEO~1\AppData\Local\Temp\cc6wXtx9.o:gmptest.c:(.text+0x1c): undefine
d reference to `__gmpz_init'
collect2: ld returned 1 exit status
Do you know anything about this error? Can anybody help me? Thank you very much!
Matteo
Just a guess, but did you include "-lgmp" to tell the compiler to link to the gmp library?

Resources