我正试图改善我的项目布局。
这里(我的CMakeLists.txt
个project(Numerical CXX)
include(cotire)
cmake_minimum_required(VERSION 3.1)
set (CMAKE_CXX_STANDARD 14)
add_executable(hw1 hw1.cpp
linalg/lu.cpp
linalg/banded.cpp
)
add_executable(hw2 hw2.cpp
linalg/cholesky.cpp
linalg/lu.cpp
linalg/banded.cpp
)
add_executable(hw3 hw3.cpp
linalg/solvers-new.cpp
linalg/cholesky.cpp
linalg/lu.cpp
linalg/banded.cpp
)
...
个文件:
lu.h
banded.h
包含lu
,因此任何需要banded
的内容都需要banded.cpp
。如上所述,这需要我的项目中的冗余。有没有办法在每次添加lu.cpp
时都不必添加dt[dt[, .I[which.min(Value)],, .(ID, Year)]$V1
][, Percent_Increase := {
tmp <- shift(Value)
(Value-tmp)/tmp
}, .(ID)]
?
答案 0 :(得分:1)
@ Amadeus的答案有效,但我认为更好的答案是将公共文件移到库中:
project(Numerical CXX)
include(cotire)
cmake_minimum_required(VERSION 3.1)
set (CMAKE_CXX_STANDARD 14)
add_library(CommonLib STATIC
linalg/lu.cpp
linalg/banded.cpp
)
add_executable(hw1
hw1.cpp
)
target_link_libraries(hw1 LINK_PUBLIC
CommonLib
)
add_executable(hw2
hw2.cpp
linalg/cholesky.cpp
)
target_link_libraries(hw2 LINK_PUBLIC
CommonLib
)
add_executable(hw3
hw3.cpp
linalg/solvers-new.cpp
linalg/cholesky.cpp
)
target_link_libraries(hw3 LINK_PUBLIC
CommonLib
)