I was using a different IDE, but decided to check this one out, as it looked easier when linking libraries into c++. So I just copied a test file I was using before, but it didn't work:
#include <stdio.h>
int main()
{
int numero, somma;
somma=0;
printf ("inserisci un numero diverso da 0 come componente della sequenza, 0 per terminare la fase di acquisizione\n");
scanf ("%d", &numero);
while (numero != 0)
{
somma=somma+numero;
printf("inserisci un numero diverso da 0 come componente della sequenza, 0 per terminare la fase di acquisione\n");
scanf("%d", &numero);
}
printf("La somma dei numeri digitati è: %d\n", somma);
FILE *tab;
tab=fopen ("tabela.csv","w");
fprintf(tab, "Hello world");
fclose (tab);
printf("inserisci un carattere\n");
scanf("%d");
}
Build log:
Files (x86)\GnuWin32\lib\libgslcblas.a"
obj\Release\main.o:main.cpp:(.text.startup+0x0): multiple definition of `main'
obj\Release\gsl.o:gsl.cpp:(.text.startup+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 1 warning(s) (0 minute(s), 0 second(s))
I get error: ld returned 1 exit status
Note: I am using Windows 8, SDK version 1.25.0, as for the complier I was using GNU GCC, what do u suggest I use? I was planning on playing around with GSL
Let's simplify things a little bit:
c++ code
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int numero, somma;
somma=0;
printf ("inserisci un numero diverso da 0 come componente della sequenza, 0 per terminare la fase di acquisizione\n");
scanf ("%d", &numero);
while (numero != 0)
{
somma=somma+numero;
printf("inserisci un numero diverso da 0 come componente della sequenza, 0 per terminare la fase di acquisione\n");
scanf("%d", &numero);
}
printf("La somma dei numeri digitati è: %d\n", somma);
return 0;
}
Build log:
-------------- Clean: Release in Test Project (compiler: GNU GCC Compiler)---------------
Cleaned "Test Project - Release"
-------------- Build: Release in Test Project (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -O2 -c "C:\Users\lucas_000\Documents\Test Project\main.cpp" -o obj\Release\main.o
mingw32-g++.exe -o "bin\Release\Test Project.exe" obj\Release\main.o -s
Output file is bin\Release\Test Project.exe with size 40.50 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
This works, but I get no exe file. Why?
It says the exe file is saved in the bin\Release folder but... when I try to open it I get:
The program can't start because libgcc_s_dw2-1.dll is missing from computer.
How can that be?
Ok, one more question: what is the preferred method of installation of GSL for working with Code::Blocks in Windows 8?
C++
#include <stdio.h>
#include <cstdlib>
#include <gsl/gsl_sf_bessel.h>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
int main()
{
/*Summing a bunch of numbers*/
int numero, somma;
somma=0;
printf ("Insert a number other than 0 in the sequence, otherwise 0 to end the insertion\n");
scanf ("%d", &numero);
while (numero != 0)
{
somma=somma+numero;
printf("Insert a number other than 0 in the sequence, otherwise 0 to end the insertion\n");
scanf("%d", &numero);
}
printf("The sum equals: %d\n", somma);
/*GSL Bessel function*/
double x = 5.0;
double y = gsl_sf_bessel_J0(x);
printf("J0(%g) = %.18e\n", x, y);
/*Writing to a text file*/
FILE *tab1;
tab1=fopen ("somma.txt","w");
fprintf(tab1, "%d", somma);
fclose (tab1);
/*Writing to a csv file*/
ofstream tab2("tabela.csv");
double A; int t;
tab2 << "Col 1;Col 2" << endl;
for (t = 0; t <= 10; t++) {
A = t+somma+y;
cout << "t = " << t << "\t\tA = " << A << endl;
tab2 << t << ";" << A << endl;
}
tab2.close();
/*End*/
system("PAUSE");
return 0;
}
Build log:
-------------- Clean: Release in Test Project (compiler: GNU GCC Compiler)---------------
Cleaned "Test Project - Release"
-------------- Build: Release in Test Project (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -O2 -ansi -I"C:\Program Files (x86)\GnuWin32\lib" -c "C:\Users\lucas_000\Documents\Test Project\main.cpp" -o obj\Release\main.o
C:\Users\lucas_000\Documents\Test Project\main.cpp:3:31: fatal error: gsl/gsl_sf_bessel.h: No such file or directory
#include <gsl/gsl_sf_bessel.h>
^
compilation terminated.
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
I solved it
means it's working now.
Build log:
-------------- Clean: Release in Test Project (compiler: GNU GCC Compiler)---------------
Cleaned "Test Project - Release"
-------------- Build: Release in Test Project (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -O2 -I"..\..\..\..\Program Files (x86)\GnuWin32\include" -c "C:\Users\lucas_000\Documents\Test Project\main.cpp" -o obj\Release\main.o
mingw32-g++.exe -o "bin\Release\Test Project.exe" obj\Release\main.o -s -static "..\..\..\..\Program Files (x86)\GnuWin32\lib\libgsl.a" "..\..\..\..\Program Files (x86)\GnuWin32\lib\libgsl.dll.a" "..\..\..\..\Program Files (x86)\GnuWin32\lib\libgslcblas.a"
Output file is bin\Release\Test Project.exe with size 669.50 KB
Process terminated with status 0 (0 minute(s), 4 second(s))
0 error(s), 0 warning(s) (0 minute(s), 4 second(s))