Author Topic: Beginner - pb with my program - C langage  (Read 9878 times)

Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Beginner - pb with my program - C langage
« on: July 06, 2015, 01:53:58 pm »
Hello everybody !!

I used tu work with Code::Blocks under windows.
I try now to use it under linux.

I've got a problem; It seems that the compilation is OK (I have installed the g++ ) but after this ... nothing.
It's probably a problem of setting, but how ?

Here is my program :

Code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define tailleMax 100000


double PGCD(double nb1,double nb2);
double PPCM(double nb1, double nb2);

int main()
{
    double nb1, nb2;
    int nb3;
    int l,choix;
    double encore =0;
    int tab[tailleMax] = {0};
    int tab2[tailleMax] = {0};

    printf("Ce programme permet de :\n\n");
    do
    {
        printf("1-calculer le PGCD de deux nombres.\n");
        printf("2-calculer le PPCM de deux nombres .\n");
        printf("3-trouver tous les diviseurs d'un nombre (jusqu'a 2.147.483.647).\n");
        printf("4-decomposer un nombre en produit de facteurs premiers (jusqu'a 2.147.483.647).\n");
        printf("5-rechercher les nombres premiers entre 2 valeurs (jusqu'a 2*10^6 en gros).\n\n");
        printf("Votre choix : ");
        for (l=0; l<=tailleMax; l++)
        {
            tab[l]=0;
            tab2[l]=0;
        }
        scanf("%d",&choix);
        switch (choix)
        {
        case 1 :
        {
            printf("\nEntrez le 1er nombre : ");
            scanf("%lf",&nb1);
            printf("Entrez le 2e nombre : ");
            scanf("%lf",&nb2);
            printf("\nLe PGCD de %.0lf et %.0lf est %.0lf\n", nb1,nb2,PGCD(nb1,nb2));
            if (PGCD(nb1,nb2)==1)
                printf("%.0lf et %.0lf sont premiers entre eux.",nb1,nb2);
            break;
        }
        case 2 :
        {
            printf("\nEntrez le 1er nombre : ");
            scanf("%lf",&nb1);
            printf("Entrez le 2e nombre : ");
            scanf("%lf",&nb2);
            printf("\nLe PPCM de %.0lf et %.0lf est %.0lf", nb1,nb2,PPCM(nb1,nb2));
            break;
        }
        case 3 :
        {
            int i,k;
            printf("\nEntrez le nombre : ");
            scanf("%d",&nb3);
            printf("\nLes diviseurs de %d sont ",nb3);
            for ( i=1 ; i<= sqrt(nb3); i++)
            {
                if ((nb3%i)==0)
                {
                    tab[i-1]=i;
                    if (i*i != nb3)
                        tab[tailleMax-i]=nb3/i;
                }
            }
            k=0;
            printf("%d",tab[0]);
            for (i=1; i<tailleMax; i++)
                if(tab[i]!=0)
                {
                    tab2[k]=tab[i];
                    printf(" - %d",tab[i]);
                    k++;
                }
            printf("\nIl y a %d diviseurs",k+1);
            if (k==1)
                printf(" : -----> %d est un nombre premier.",nb3);
            break;
        }
        case 4 :
        {
            int i,j,k,x;

            printf("\nEntrez le nombre : ");
            scanf("%d",&nb3);
            for ( i=1 ; i<= sqrt(nb3); i++)
            {
                if ((nb3%i)==0)
                {
                    tab[i-1]=i;
                    if (i*i != nb3)
                        tab[tailleMax-i]=nb3/i;
                }
            }
            k=0;
            for (i=1; i<tailleMax; i++)
                if(tab[i]!=0)
                {
                    tab2[k]=tab[i];
                    k++;
                }
            printf("\n");
            if (k==1)
                printf("-----> %d est un nombre premier.",nb3);
            else
            {
                j=0;
                printf("%d = %d",nb3, tab2[0]);
                x=nb3/tab2[0];
                for (j=0; j<k; j++)
                    while ((x%tab2[j])==0)
                    {
                        printf(" x %d",tab2[j]);
                        x=x/tab2[j];
                    }
            }
            break;
        }
        case 5 :
        {
            int i,k,max,min,x;
            int *entier=NULL;

            printf("\nEntrez le plus petit nombre : ");
            scanf("%d",&min);
            do
                {
                    printf("Entrez le plus grand  nombre (il doit etre superieur ou egal a %d) : " ,min+2);
                    scanf("%d",&max);
                }
            while (max<=min+1);
            entier = malloc(max*sizeof(int)); // allocation dynamique d'un tableau ; il aura max cases de int.
            if (entier==NULL)
                exit(0);
            for (i=0; i<max; i++)
                entier[i]=i;
            i=1;
            do
            {
                i++;
                if (entier[i]!=0)
                {
                    k=2;
                    while (k*i<=max-max%entier[i])
                    {
                        entier[k*i]=0;
                        k++;
                    }
                }
            }
            while (i*i<max);
            printf("\nLes nombres premiers compris entre %d et %d sont : ",min,max);
            k=0;
            for (i=min; i<=max; i++)
                if ((entier[i]!=0)&&(i>1))
                {
                    printf("%d ",entier[i]);
                    k++;
                }
            if (k==0)
                printf("\n\nIl n'y a aucun nombre premier.\n");
            else
                printf("\n\nIl y a %d nombre(s) premier(s).\n",k);

            if (min<=0)
              min=2;
            FILE *fichier=NULL;
            fichier=fopen("nombrespremiers.txt","w+");
            if(fichier!=NULL)
             {
                for(i=min; i<max; i++)
                    if (entier[i]!=0)
                        fprintf(fichier,"%d ",entier[i]);
                rewind(fichier);
                for(i=0; i<10; i++)
                {
                    fscanf(fichier,"%d",&x);
                    printf("%d ",x);
                }
            }
            else
                printf("Impossible d'ouvrir le fichier Nombres.txt");
            free(entier);
            break;

        }
        default :
            exit (0);
        }
        printf("\n\nVoulez-vous recommencer ? (oui = 1 , non = autre touche) : ");
        scanf("%d",&choix);
        if (choix==1)
            encore = 1;
        else
            encore = 0;
        printf("\n--------------------------------------------------------------------------------\n");
        printf("--------------------------------------------------------------------------------\n");
        printf("\n");
    }
    while (encore==1);
    return 0;
}
double PGCD(double nb1,double nb2)
{
    double dividende, diviseur, reste;
    dividende = nb1;
    diviseur = nb2;
    do
    {
        reste = dividende - diviseur*floor(dividende/diviseur);
        dividende = diviseur ;
        diviseur = reste;
    }
    while (reste != 0);
    return dividende;
}
double PPCM(double nb1, double nb2)
{
    return nb1*nb2/PGCD(nb1,nb2);
}


And the log :

Code
||=== Générer: Release in Diviseurs (compiler: GNU GCC Compiler) ===|
obj/Release/main.o:main.c|| référence indéfinie vers « _floor »|
obj/Release/main.o:main.c|| référence indéfinie vers « ___chkstk »|
obj/Release/main.o:main.c|| référence indéfinie vers « ___main »|
obj/Release/main.o:main.c|| référence indéfinie vers « _puts »|
obj/Release/main.o:main.c|| référence indéfinie vers « _puts »|
obj/Release/main.o:main.c|| référence indéfinie vers « _puts »|
obj/Release/main.o:main.c|| référence indéfinie vers « _puts »|
obj/Release/main.o:main.c|| référence indéfinie vers « _puts »|
obj/Release/main.o:main.c|| encore plus de références indéfinies suivent vers « _puts »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _scanf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _scanf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _scanf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _malloc »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _fopen »|
obj/Release/main.o:main.c|| référence indéfinie vers « _fprintf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _rewind »|
obj/Release/main.o:main.c|| référence indéfinie vers « _fscanf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _free »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _scanf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _sqrt »|
obj/Release/main.o:main.c|| référence indéfinie vers « _putchar »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _scanf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _sqrt »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _scanf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _scanf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _scanf »|
obj/Release/main.o:main.c|| référence indéfinie vers « _puts »|
obj/Release/main.o:main.c|| référence indéfinie vers « _puts »|
obj/Release/main.o:main.c|| référence indéfinie vers « _putchar »|
obj/Release/main.o:main.c|| référence indéfinie vers « _printf »|
||Plus d'erreurs suivent mais ne sont pas montrées.|
||Editer la limite maximale du nombre d'erreurs dans les options du compilateur ...|
||=== Build échoué: 50 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Sorry it's in french but maybe you can guess what it means.
A problem of path ? How to configure it ?

Thank you for your help  and sorry for my english  ;)

JP

Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #1 on: July 06, 2015, 02:00:07 pm »
Sorry a mistake : here is the log report :


Code
-------------- Générer: Release in Diviseurs (compiler: GNU GCC Compiler)---------------

g++  -o bin/Release/Diviseurs obj/Release/main.o  -s 
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o: dans la fonction « _start »:
(.text+0x18): référence indéfinie vers « main »
obj/Release/main.o:main.c:(.text+0x22): référence indéfinie vers « _floor »
obj/Release/main.o:main.c:(.text+0x8b): référence indéfinie vers « ___chkstk »
obj/Release/main.o:main.c:(.text+0x90): référence indéfinie vers « ___main »
obj/Release/main.o:main.c:(.text+0xbf): référence indéfinie vers « _puts »
obj/Release/main.o:main.c:(.text+0xcb): référence indéfinie vers « _puts »
obj/Release/main.o:main.c:(.text+0xd7): référence indéfinie vers « _puts »
obj/Release/main.o:main.c:(.text+0xe3): référence indéfinie vers « _puts »
obj/Release/main.o:main.c:(.text+0xef): référence indéfinie vers « _puts »
obj/Release/main.o:main.c:(.text+0xfb): encore plus de références indéfinies suivent vers « _puts »
obj/Release/main.o:main.c:(.text+0x107): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x13a): référence indéfinie vers « _scanf »
obj/Release/main.o:main.c:(.text+0x16a): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x181): référence indéfinie vers « _scanf »
obj/Release/main.o:main.c:(.text+0x19b): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x1b2): référence indéfinie vers « _scanf »
obj/Release/main.o:main.c:(.text+0x1d2): référence indéfinie vers « _malloc »
obj/Release/main.o:main.c:(.text+0x28c): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x2cb): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x2f9): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x31c): référence indéfinie vers « _fopen »
obj/Release/main.o:main.c:(.text+0x36e): référence indéfinie vers « _fprintf »
obj/Release/main.o:main.c:(.text+0x38b): référence indéfinie vers « _rewind »
obj/Release/main.o:main.c:(.text+0x3b3): référence indéfinie vers « _fscanf »
obj/Release/main.o:main.c:(.text+0x3ca): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x3dc): référence indéfinie vers « _free »
obj/Release/main.o:main.c:(.text+0x3ed): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x404): référence indéfinie vers « _scanf »
obj/Release/main.o:main.c:(.text+0x465): référence indéfinie vers « _sqrt »
obj/Release/main.o:main.c:(.text+0x4b0): référence indéfinie vers « _putchar »
obj/Release/main.o:main.c:(.text+0x4da): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x518): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x54e): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x565): référence indéfinie vers « _scanf »
obj/Release/main.o:main.c:(.text+0x57c): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x5dd): référence indéfinie vers « _sqrt »
obj/Release/main.o:main.c:(.text+0x60c): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x63c): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x659): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x677): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x688): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x69f): référence indéfinie vers « _scanf »
obj/Release/main.o:main.c:(.text+0x6ab): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x6c2): référence indéfinie vers « _scanf »
obj/Release/main.o:main.c:(.text+0x72e): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x73a): référence indéfinie vers « _printf »
obj/Release/main.o:main.c:(.text+0x751): référence indéfinie vers « _scanf »
obj/Release/main.o:main.c:(.text+0x76b): référence indéfinie vers « _puts »
obj/Release/main.o:main.c:(.text+0x777): référence indéfinie vers « _puts »
obj/Release/main.o:main.c:(.text+0x783): référence indéfinie vers « _putchar »
obj/Release/main.o:main.c:(.text+0x79c): référence indéfinie vers « _printf »
Process terminated with status 1 (0 minute(s), 0 second(s))
50 error(s), 0 warning(s) (0 minute(s), 0 second(s))


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Beginner - pb with my program - C langage
« Reply #2 on: July 06, 2015, 02:53:42 pm »
Hello,
thank you for your detailed report. I don't speak french (or whatever your language is) but i think the error message you get is "undefined reference to floor" *)
you have to add the math library to the linker. ( http://stackoverflow.com/questions/14743023/c-undefined-reference-to-floor )

You can do this in c::b by adding "-lm" (without quotes) under Project->Build options->Linker settings -> Other linker options

*) I personally hate the localized error output of the new gcc versions. For beginners it is nearly impossible to find the errors by googeling it, because all forums are (luckily) in english. To set the output language (only output of gcc, not the output of your program) of the gcc you can follow this instruction http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_can_I_change_the_language_of_the_compiler_.28gcc.29_output_to_english.3F So if you get other errors they can for 90% fixed by c&p the error in google...

greetings

Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #3 on: July 06, 2015, 04:23:27 pm »
Thank you BlueHazzard.

I speak french, but here I can also try another language !  ;)

Looking more carefully, I see this information from the log report :

Code
 référence indéfinie vers « main »

wich means undefined reference to "main" !!! It's the main that it's trying to compile, or what ?
Don't you think here is a problem ?  :o

I tried to add the math library, without any success ...  ???

I tried also to add the -lm as a link ... not better.

But as a beginner all of this is not so simple and maybe I made an error somewhere ?

Thanks for your help and have a good day (4 pm in France)

JP


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Beginner - pb with my program - C langage
« Reply #4 on: July 06, 2015, 04:30:11 pm »
can you make a clean rebuild (the blue arrows, or Build -> Rebuild) and post the build log? (with the inserted -lm options in the linker settings. Make sure on the left site (of the linker options dialog) is selected your project, not a sub target)

greetings from a country near french ;)
« Last Edit: July 06, 2015, 04:31:49 pm by BlueHazzard »

Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #5 on: July 06, 2015, 04:42:46 pm »
Here is it :  ::)


Code
-------------- Nettoyer: Release in Diviseurs (compiler: GNU GCC Compiler)---------------

Cleaned "Diviseurs - Release"

-------------- Générer: Release in Diviseurs (compiler: GNU GCC Compiler)---------------

gcc -Wall -O2  -c "/media/jp/450Go/Programmation C/Console/Diviseurs/main.c" -o obj/Release/main.o
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c: In function ‘main’:
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:33:14: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&choix);
              ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:39:18: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lf",&nb1);
                  ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:41:18: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lf",&nb2);
                  ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:50:18: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lf",&nb1);
                  ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:52:18: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lf",&nb2);
                  ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:60:18: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&nb3);
                  ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:90:18: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&nb3);
                  ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:130:18: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&min);
                  ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:134:26: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
                     scanf("%d",&max);
                          ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:182:27: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
                     fscanf(fichier,"%d",&x);
                           ^
/media/jp/450Go/Programmation C/Console/Diviseurs/main.c:196:14: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&choix);
              ^
g++  -o bin/Release/Diviseurs obj/Release/main.o  -lm -s 
Output file is bin/Release/Diviseurs with size 9,49 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 11 warning(s) (0 minute(s), 0 second(s))
 

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Beginner - pb with my program - C langage
« Reply #6 on: July 06, 2015, 04:56:12 pm »
so everything works like a charm  ;D ....

greetings

Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #7 on: July 06, 2015, 06:07:01 pm »
I made another 'build and run' of my program, and here is the result :


Code
-------------- Générer: Release in Diviseurs (compiler: GNU GCC Compiler)---------------

La cible est à jour.
Nothing to be done (all items are up-to-date).


-------------- Lancer: Release in Diviseurs (compiler: GNU GCC Compiler)---------------

Checking for existence: /media/jp/450Go/Programmation C/Console/Diviseurs/bin/Release/Diviseurs
Exécution de: xterm -T Diviseurs -e /usr/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. /media/jp/450Go/Programmation\ C/Console/Diviseurs/bin/Release/Diviseurs  ( dans /media/jp/450Go/Programmation C/Console/Diviseurs/.)
Process terminated with status 255 (0 minute(s), 0 second(s))

Nice probably, but I see nothing !  :-\
Everything works like a charm ?  :o

The 'console' does not open. I don't understand what's happening  >:(    ;D

If probably forgot something stupid, I don't know ....

Have a nice day and thanks again for your help.

JP

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Beginner - pb with my program - C langage
« Reply #8 on: July 06, 2015, 06:18:00 pm »
Either install xterm or switch to another terminal-emulator in "Settings -> Environmant -> General settings".
You have to chose one, that is installed on your system of course.

Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #9 on: July 07, 2015, 08:57:02 am »
Thank you Jens for your answer.  :)

The default terminal was Xterm (and probably it's not installed). So I put the xfce4 terminal and now it's OK.

You gave me the answer I was looking for  :D

have a nice day !  ;D



Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #10 on: July 07, 2015, 11:33:17 am »
I've got a last problem and maybe you can help me ;

It seems that c::b does not recognize the SDL library.
Is it installed ? If not how to do this ?

Here is the result of my compilation :

Code
gcc   -c /home/jp/Documents/Mandelbrot.c -o /home/jp/Documents/Mandelbrot.o
/home/jp/Documents/Mandelbrot.c:4:21: fatal error: SDL/SDL.h: Aucun fichier ou dossier de ce type   <- no such file or directory (I translate)
                     ^
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))

So what should I do ?  :o

Thanks again for your help.

Have a nice day.  ;)
JP



Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #12 on: July 07, 2015, 10:22:30 pm »
Thanks for the link, BlueHazzard.

I try but for the moment without success.
Here is what I did: (I am under linux)

1) I saw that "libsdl1.2debian" is the SDL lib package installed.
2) I searched where in the computer is the SDL library. I founded this : /usr/lib/i386-linux-gnu/libSDL-1.2.so.0.11.4   Is it the library I need ? It's not a .a or .so or .lib because of the 0.11.4 !
3) I created an SDL project with codeblocks and put it here : /home/jp/Documents/Mandelbrot linux/
4) then in Project->Build Options->Search directories->Compiler , I put this : /home/jp/Documents/Mandelbrot linux/   (correct ?)
5) then in Project->Build Options->Search directories->Linker, ...  I don't know where is my compiled library !!!

So I stopped here for the moment.
Maybe somebody can have an idea or tell me what's wrong  :)

Thanks again for your help. English is not my first language  ;)
JP


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Beginner - pb with my program - C langage
« Reply #13 on: July 08, 2015, 12:13:17 am »
https://www.youtube.com/watch?v=CiEwXjq4_yo

http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks

http://ubuntuforums.org/showthread.php?t=453171

http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/

http://www.codewithc.com/how-to-setup-sdl-in-codeblocks/

ecc. ecc. google is your friend...

4) then in Project->Build Options->Search directories->Compiler , I put this : /home/jp/Documents/Mandelbrot linux/   (correct ?)
no, there should be the path to the sdl include directory
http://stackoverflow.com/questions/10488775/sdl-h-no-such-file-or-directory-found-when-compiling

5) then in Project->Build Options->Search directories->Linker, ...  I don't know where is my compiled library !!!
probably somewhere in /usr/lib....

2) I searched where in the computer is the SDL library. I founded this : /usr/lib/i386-linux-gnu/libSDL-1.2.so.0.11.4   Is it the library I need ? It's not a .a or .so or .lib
probably there is somewhere a symlink to a libSDL.... (you can google that to)

the simple way is probably:
you can also use the
Code
`sdl-config --libs`
command. Copy it (with the single quotes) to Project->Build options->Linker settings-> Other Linker options
and
Code
`sdl-config --cflags`
to  Project->Build options-> Compiler Settings-> Other options (also with the quotes)
This will tell c::b all necessary cflags (compiler flags like include directories) and libs (also the path)

Note: i have never used SDL, so this information can be outdated, or non functional... You can search the c::b forum for SDL and you will find tons of answers...

greetings
« Last Edit: July 08, 2015, 12:15:45 am by BlueHazzard »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Beginner - pb with my program - C langage
« Reply #14 on: July 08, 2015, 05:57:28 am »
If there is only the versioned *.so.xxx-file but not he symlink to *.so, it usually means that the development-package(s) is/are missing on your system.

Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #15 on: July 08, 2015, 02:14:34 pm »
Thank you Jens and BlueHazzard.  :D :D

I installed the libsdl dev package and suddenly the compilation is OK !  :)
In the Project->Build options->Linker settings-> Other Linker options ,  `sdl-config --libs` appears.
In the  Project->Build options-> Compiler Settings-> Other options, `sdl-config --cflags` appears.

So this part is a success and the SDL library is recognised.

So I ran the Mandelbrot program I made with c::b under windows (worked good).
It begins well, the Mandelbrot set appears, and suddenly when I use the mouse ( left-clic and right-clic ), the program stops  :o

Do you think that something else could be missing on my system ? (there are many SDL packages ...)

Her are the message the console returns to me :

Code
*** Error in `/home/jp/Documents/Mandel/bin/Debug/Mandel': double free or corruption (!prev): 0x08341f98 ***
Aborted

Process returned 134 (0x86)   execution time : 12.095 s
Press ENTER to continue.

Do you know what means " double free or corruption (!prev)" ?

Thanks again for your help if you've got an idea.
Have a good day.

JP

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Beginner - pb with my program - C langage
« Reply #16 on: July 08, 2015, 02:58:43 pm »
Thank you Jens and BlueHazzard.  :D :D

I installed the libsdl dev package and suddenly the compilation is OK !  :)
In the Project->Build options->Linker settings-> Other Linker options ,  `sdl-config --libs` appears.
In the  Project->Build options-> Compiler Settings-> Other options, `sdl-config --cflags` appears.

So this part is a success and the SDL library is recognised.

So I ran the Mandelbrot program I made with c::b under windows (worked good).
It begins well, the Mandelbrot set appears, and suddenly when I use the mouse ( left-clic and right-clic ), the program stops  :o

from this point the work of c::b is done, and for problems after this point you need a other forum for questions... we can not help with 3 party libraries, because there are simply to much and if we answer each question the forum will get bloated...

so i recommend you to ask this question on stack overflow or a sdl forum...

Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #17 on: July 08, 2015, 04:21:40 pm »
OK BlueHazzard.

Thanks again for your help and for the advice ! :)

I try with another forum and surch with google of course.

Have a nice day (and good nights too !)  8)

JP

Offline marcelinux

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Beginner - pb with my program - C langage
« Reply #18 on: July 09, 2015, 08:15:12 am »
Or you can use the debuger.
I just need learn a little bit more. Thank you for your help.

Offline jpapot

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Beginner - pb with my program - C langage
« Reply #19 on: July 09, 2015, 02:12:21 pm »
Hello.

I posted my problem on the Stack Overflow forum, and someone founded. (A line had to be suppressed)
The program runs even better now than before !!!

It calculates and displays the Mandelbrot set. You can use the left clic of the mouse to zoom inside the image ( down and up to draw a square)

Thanks to Marcellinux, BlueHazzard and Jens for their answers.
If someone is interested, I can post the code as a gift.  ;D

(It's for a 1680x1050 pxl screen, but one can change those valors at the beginning). It's probably possible to make the program better of course  ;)

Have a nice day.  8)

JP