How to write system-independent code when there are ways?

Let's say I create a project that uses a specific library, and I have to provide a path for this library when linking. On the command line or makefile, I could:

g++ ... -L/path/to/mylibrary

I will also send this project to someone who wants to use it. The path in their system may not be the same as mine. They may use a different file path.

How can I make sure that the library path works for both my computer and the recipient of my project?

+4
source share
3 answers

. . , , CMake, , - . , Boost.Jam, autoconf, .

, , , . , . , , , script.

CMake , Boost:

cmake_minimum_required (VERSION 2.8)
project (ExampleWithBoost)

find_package(Boost 1.46 COMPONENTS thread program_options filesystem REQUIRED)

# Add the boost directory to the include paths:
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
# Add the boost library directory to the link paths:
link_directories(${Boost_LIBRARY_DIRS})

# Add an executable target (for compilation):
add_executable(example_with_boost example_with_boost.cpp)
# Add boost libraries to the linking on the target:
target_link_libraries(example_with_boost ${Boost_LIBRARIES})

cmake find_package script ( Boost CMake), ( ), , , . find_package , , CMake (, ).

, , "example_with_boost.cpp", . , , CMake ( , ). - , , , ( , , , - - IDE, , Visual Studio).

+3

premake, - make : Visual Studio, Gcc

http://industriousone.com/what-premake

CMake -

http://www.cmake.org/

0

, , Makefile , : linux.make, darwin.make, cygwin.make ..

, CMake, , , .

0

Source: https://habr.com/ru/post/1541967/


All Articles