Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3394924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:13:42+00:00 2026-05-18T04:13:42+00:00

I currently have a library-like .c file (that’ll be shown below). I have 2

  • 0

I currently have a “library-like” .c file (that’ll be shown below). I have 2 questions about it:

  1. If I want to see if it compiles well for itself, how can I do it? If I try to gcc it, it will always give a “no main” error, which makes sense, but raises the problem of knowing if a given .c file will compile well or not in “isolation”. Can I safely conclude that if the only error raised by the compiler is the “no main” one, my file is fine? An example of where compiling .c files in isolation could be nice would be to determine which includes are in excess, in here.

  2. Is there a point in a simple file like this to define a header with its method / struct declarations and then have such tiny .c file with the code implementation in it?

    #ifndef SEMAFOROS
    #define SEMAFOROS
    
    
    #include <signal.h>
    #include <sys/mman.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <semaphore.h>
    
    
    typedef struct {
        sem_t* id;
        char* nome;
    } Semaforo;
    
    
    inline void lock(Semaforo* semaforo) {
        sem_wait(semaforo->id);
    }
    
    
    inline void unlock(Semaforo* semaforo) {
        sem_post(semaforo->id);
    }
    
    
    Semaforo* criarSemaforo(char* nome) {
        Semaforo* semaforo = (Semaforo*)malloc(sizeof(Semaforo));
        semaforo->id = sem_open(nome, O_CREAT, 0xFFFFFFF, 1);
        semaforo->nome = nome;
    }
    
    
    void destruirSemaforo(Semaforo* semaforo) {
        sem_close(semaforo->id);
        sem_unlink(semaforo->nome);
    
    
    
    free(semaforo);
    

    }

    #endif

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:13:42+00:00Added an answer on May 18, 2026 at 4:13 am

    To compile it without linking (doesn’t require a main entry point):

    cc -c file.c -o file.o
    

    Even for a small file that defines routines that will be called from other source files you still want a header file. The header file is how the compiler knows the interface to the routines before the linker ties it all together. If you don’t have declarations for functions that are external then the compiler has to make assumptions (usually wrong) about the data types of the parameters. You can declare the functions in every source file where they are used, but the point of header files is so that you just do it once in the header file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We currently have a project that consists of multiple applications as well as a
I have an interesting problem. I currently have a basic template library that renders
I am currently building a Neural Network library. I have constructed it as an
I currently have an MS Access application that connects to a PostgreSQL database via
We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
To start I would like to clarify that I'm not extremely well versed in
I have a C# application that needs to be run several thousand times. Currently
I want to use an 3rd party library without using its header file. My
I have written a Python extension library in C and I am currently using
Recently I stumbled across this pretty slick JS library called nodeJS that acts like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.