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 8173175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:02:56+00:00 2026-06-06T22:02:56+00:00

I have three files: lib.c lib.h => They should be built as a .so

  • 0

I have three files:

lib.c lib.h => They should be built as a .so file
client.c => This should be built as an executable.

Inside the client.c I include the lib.h file so as to get the declarations of the functions defined under lib.c

Can someone tell me the exact CMakeLists file that I should be using so that the source area is uncluttered with Cmake’s temporary files and the binaries and the libraries (.dlls in case of windows I believe) generated in separate build and binary directories ?

  • 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-06-06T22:02:57+00:00Added an answer on June 6, 2026 at 10:02 pm

    Cmake builds on separate build directories by default (I did not test this example):

    PROJECT(myproject)
    CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
    
    SET(mylibSRCS lib.c)
    SET(myprogSRCS client.c)
    
    ADD_LIBRARY(mylib ${mylibSRCS})
    ADD_EXECUTABLE(myprog ${myprogSRCS})
    
    TARGET_LINK_LIBRARIES(myprog mylib)
    

    You do:

    mkdir build
    cd build
    cmake ..
    make
    

    Everything would be under build.

    Update: As mentioned by @chryss below, if you want the .so file to be generated, the command should be:

    ADD_LIBRARY(mylib SHARED ${mylibSRCS})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three files, a main .cpp file: #include <stdio.h> #include myClass.h int main()
I have three files: movie.h (header); movie.cpp (implementation file); lab9.cpp (driver file using movie
If I have three files index.php file.php and fns.php First example (it works): index.php
My have three .cpp files and their headers. //a.cpp #include a.h #include b.h void
Suppose that I have those three files: a.h //a.h header #include <stdio.h> int int_variable;
I have three big header files (4.5MB and more), with huge static arrays inside.
I have a server, and Client that are working fine, they transfer file to
I have three files: one called sql.php witch has a class db that I
I have three files in a folder 'test' one.php two.php print.html And i have
I have three source files in a folder. I simply want to compile them

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.