How to compile a complex program with just text-editor and compiler (GCC)

I can compile a simple program which has few cpp files, header files. But I don't know how to compile a bigger program with many things else such as: static lib, dynamic lib, bin/sav file (extend file for program), open source code, etc.

I think static lib doesn't matter to me much.
But dynamic lib is a huge question. Where should I put the dynamic files so my program can read? In OS folder or the same folder my program works?

Open source code is another problem too. How to import theme? Some open source code official site said just include their header is ok. But what about dll file (yeah, dynamic file?)

For very real example. My program need to add GLFW (http://www.glfw.org/docs/latest/quick.html) to the code. But they told me only add header. So it wonders me what about those dll and a file? What am I going to do with it?

I have tried to google it, but as far as I see, they only compiled around 3 files (2 cpp and 1 h).

(I even not mention folder structure. I means, some games/apps has a lot complex folder structure beside bin folder. How did they do that? Do I need to be like that?)
Use something like CMake to organize dependencies and generate project files. It can generate a Visual Studio solution, Unix Makefiles, etc.

You'll likely need a top-level CMakeLists.txt file to set proper compiler flags and name the "solution".

CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(MySolution)

set( GccDir /usr )
set( CAllFlags "-m64 -DLINUX -DX86 -DX8664" )
set( CxxFlags "-std=c++11 -Wall" )

set( CMAKE_C_COMPILER ${GccDir}/bin/gcc )
set( CMAKE_CXX_COMPILER ${GccDir}/bin/g++ )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CAllFlags} ${CxxFlags}" )

# Configure to put executable in top level bin directory
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

# Descend recursively into other directories to look for more CMakeLists.txt files
add_subdirectory( src )


You'll have a directory named "src", as per last line of top-level file, with another CMakeLists.txt file. The project file may look something like

src/CMakeLists.txt
set( ProjectName MyProject )

set( Sources 
    Blah.cpp
    Blah.h
)

include_directories(
    place/to/look/for/headers
    place/to/look/for/more/headers
)

# Or add_executable
add_library( ${ProjectName} ${Sources} )

target_link_libraries( ${ProjectName} 
    glfw_library_name
    some_other_dependency
)


CMake is a really powerful generator, and can easily generate for many IDEs on many platforms. Unfortunately idk if there are any actual good tutorials.
Did you read http://www.glfw.org/docs/latest/build_guide.html


Overall, the compiler installation tends to set a "default search path", a list of system folders that the linker checks in order to link a mentioned library. If third party libraries do install themselves into those folders, then they can be found.

A third party library that is not there, is where-ever you did install it to. Then you add compiler/linker options to tell those tools where the headers and library files can be found.


You most likely do have the 'make' utility that reads instructions from a 'Makefile' and calls compiler. The instructions would include the compiler options.

There are multiple tools (e.g. GNU autotools, CMake) that have their own (platform-independent) instructions that they follow to generate (platform-dependent) Makefile for the make.
Ok, thank you guys for your nice support. But I still a bit confused about it. And yet, I don't know how to express.
Anyway, maybe it's still too soon for me to learn these things.
Can I come back will a proper project?
Very appreciate your helps.
My program need to add GLFW [...] to the code. [...] So it wonders me what about those dll and a file?

Is your problem the compilation or the deployment?

a) If your problem is building your project, the answer varies according to your IDE.
For example, by standard option, Qt Creator makes a folder where it puts the makefiles and, inside that, other two folders, one for the debug built and one for the release built, where it adds the object files and the final executable. If you add your dll(st) here, the OS is usually able to find them.
Graphically (Qt Creator):
myproject
         - headers
         - sources
         - (whatever)
build-myproject-[date_hours_...]-...
                                    debug
                                         - *.o
                                         - *. exe
                                         - you can add your dll(s) here
                                    release
                                           - *.o
                                           - *. exe
                                           - you can add your dll(s) here
                                    - makefiles
                                    - (whatever)


b) If your question is about deployment (that is: if your project is production ready and you want to start its distribution), that’s another kettle of fish, far harder to work out.
You need to plan from the very beginning in which operative systems it’s going to be installed, if you want to make it ‘portable’ (everything in a directory) or installed according to specific OS rules; if you’re going to provide updates, an un-install utility, patches...
(Besides, if you include other people’s code, when their developers provide an update, perhaps you’ll be require to ‘transmit’ it to your clients, because it could solve potential security issues.)

While in Linux you can usually cope with those requirements by makefiles, in Windows things could be more complicated and you could evaluate ready made tools that do it.

If you could be more specific, you’d get better answers.

Happy coding!

Topic archived. No new replies allowed.