Author Topic: New to Code:.Blocks  (Read 9263 times)

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
New to Code:.Blocks
« on: July 22, 2015, 11:27:52 pm »
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:

Code

#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:
Code
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
« Last Edit: July 22, 2015, 11:57:45 pm by lbertolotti »
Languages: C/C++, SQL, HTML, VB, Python and R

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7590
    • My Best Post
Re: New to Code:.Blocks
« Reply #1 on: July 22, 2015, 11:33:59 pm »
Please read and follow the FAQ
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Please use code tags when posting code or build logs!

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: New to Code:.Blocks
« Reply #2 on: July 22, 2015, 11:58:24 pm »

Please use code tags when posting code or build logs!

Tim S.

Better now?
Languages: C/C++, SQL, HTML, VB, Python and R

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: New to Code:.Blocks
« Reply #3 on: July 23, 2015, 12:34:55 am »
Given your programs simplicity, I would just use CB's new project wizard to create a new console project and then just copy and paste your code as needed.

That will save you time from having to tell CB what you want, where you want it, and where everything else is...

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: New to Code:.Blocks
« Reply #4 on: July 23, 2015, 01:33:52 am »

Please use code tags when posting code or build logs!

Tim S.

Better now?

formatting is perfect  :D  , but we still need a full rebuild log to know exactly what you are doing

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: New to Code:.Blocks
« Reply #5 on: July 23, 2015, 01:46:12 am »
formatting is perfect  :D  , but we still need a full rebuild log to know exactly what you are doing
No, we don't need the full rebuild log.
The linker has told him exactly what the problem is.
There are two main functions - one in the main.cpp and one in gsl.cpp obivously this is not allowed,
so one of them should be removed either by deleting it in the code or by removing one of the files from the project.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: New to Code:.Blocks
« Reply #6 on: July 23, 2015, 02:36:49 am »
Let's simplify things a little bit:

c++ code

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:

Code


-------------- 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?
« Last Edit: July 23, 2015, 02:43:20 am by lbertolotti »
Languages: C/C++, SQL, HTML, VB, Python and R

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: New to Code:.Blocks
« Reply #7 on: July 23, 2015, 10:53:25 am »
i never got this warning...
but 1 second of using google gave me this: http://stackoverflow.com/questions/4702732/the-program-cant-start-because-libgcc-s-dw2-1-dll-is-missing with the easiest solution:
Quote
Code::Blocks: add '-static' in settings->compiler->Linker settings->Other linker options.

why do you add "-fexceptions" to the compiler settings? Aren't they enabled by default? (Ah, i see you are trying to compile pure c code with c++, but i think if you are using g++ as compiler then exception are enabled by default, also if your code is pure c (i don't know this exactly), i don't think that g++ can differentiate between c and c++ code)

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: New to Code:.Blocks
« Reply #8 on: July 23, 2015, 03:38:57 pm »
Well that worked, but wouldn't it be more correct to change the compiler?
« Last Edit: July 23, 2015, 03:53:46 pm by lbertolotti »
Languages: C/C++, SQL, HTML, VB, Python and R

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: New to Code:.Blocks
« Reply #9 on: July 23, 2015, 05:58:11 pm »
Well that worked, but wouldn't it be more correct to change the compiler?
so you want to compile your program with the c compiler?

then you have to select c at the new project wizard....

(or save your file as .c because c::b distinguishes c and c++ files by their extension...)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7590
    • My Best Post
Re: New to Code:.Blocks
« Reply #10 on: July 23, 2015, 06:08:54 pm »
Well that worked, but wouldn't it be more correct to change the compiler?
so you want to compile your program with the c compiler?

then you have to select c at the new project wizard....

(or save your file as .c because c::b distinguishes c and c++ files by their extension...)

Also, need to change the CB Compiler config to link with the gcc instead of g++ command.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: New to Code:.Blocks
« Reply #11 on: July 23, 2015, 07:22:57 pm »
Ok, one more question: what is the preferred method of installation of GSL for working with Code::Blocks in Windows 8?

C++

Code
#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:

Code

-------------- 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))
 
« Last Edit: July 23, 2015, 08:48:26 pm by lbertolotti »
Languages: C/C++, SQL, HTML, VB, Python and R

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: New to Code:.Blocks
« Reply #12 on: July 23, 2015, 08:23:55 pm »
Try reading the FAQ on the wiki and especially this page: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F

Also read the manual of your compiler and understand how it handles #includes.
And lastly try to understand what is the difference between "" and <> in the include directive.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: New to Code:.Blocks
« Reply #13 on: July 23, 2015, 08:39:42 pm »
And always post the full build log if you want some help...

greetings

Offline lbertolotti

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: New to Code:.Blocks
« Reply #14 on: July 23, 2015, 08:49:13 pm »
And always post the full build log if you want some help...

greetings

Done.
Languages: C/C++, SQL, HTML, VB, Python and R