Menu

create a library in c - help me, please!!

Lya
2008-03-12
2012-09-26
  • Lya

    Lya - 2008-03-12

    How do I create a library in dev-c? I created the following files in c:

    // utils.h
    extern int parImpar(int n);

    //utils.c

    include "utils.h"

    int parImpar(int n)
    {
    if (n%2==0)
    return (1); / Numero é par/
    else
    return (0); // Numero é par
    }

    //prin.c

    include "utils.h"

    include <stdio.h>

    include <stdlib.h>

    int main()
    {
    int b;
    printf("\n\n\tIndique um numero: ");
    scanf("%d",&b);

    if (parImpar(b) == 1)
       printf(&quot;\n\n\n\tO numero e par\n\n\n\n\n&quot;);
    else
        printf(&quot;\n\n\n\tO numero e impar\n\n\n\n\n&quot;);
    system(&quot;pause&quot;);
    return(0);
    

    }

    But when I compile the console project I obtain the error "[Build Error] [utils.o] Error 1".
    Can you help me to resolve this error?

    thanks
    Lya

     
    • cpns

      cpns - 2008-03-13

      1) What makes you think you need to create a library?

      2) Libraries should not normally contain a main() function unless you are building an application framework perhaps.

      3) What would be the point of a library containing just one function in any case?

      4) The so called error you posted merely indicates that the build failed. The reason for failure will be indicated by the Compile Log which is what you should have posted.

      What I suspect you really want to do is simply create a single executable form multiple source files. For that each source must be separately compiled and then linked. Fortunately Dev-C++ will manage this for you by creating a 'project' to manage your build. File->New->Project. Once you have created your project, you can configure it and add sources via the "Project" menu.

      Incidentally if you really did want to create a library you do it the same way, (i.e. File->New->Project)

      Is it just me that thinks that this is blindingly obvious and anyone with sufficient curiosity to have explored the Dev-C++ menus and dialogs would have figured this out for themselves? ... Probably just me.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.