There are several ways. You can create a script file (Batch in Windows, Bash in Linux, for example) to automate this compilation. You can also use a Makefile . But I suggest you use a configuration manager like CMake to generate the project files that you will use in the appropriate platform and compiler.
When creating the CMake file there is a command called find_package
that " magically "finds the dependencies of a library that also expose a" CMake interface "(as is the case with OpenCV). And there's also a command called target_link_libraries
that does exactly what you want: linka the right libraries. So you can do something like this in your CMake script:
. . .
find_package(OpenCV REQUIRED core highgui imgproc)
include_directories(${OpenCV_INCLUDE_DIRS})
. . .
target_link_libraries(MeuProjeto ${OpenCV_LIBS})
. . .
Then, when you generate the project (that is, the Visual Studio project, if you use this compiler, or the Makefile if you use some other), CMake will only find where the OpenCV libraries are and reference in your project. And when you compile later, with this project generated, everything will work transparently.
CMake has a boring learning curve (especially since the documentation is not there, in my opinion), but it's worth it. If it will help, this my project in Github uses OpenCV in C ++ and employs CMake to do exactly what I suggested above. Take a look at the CMakeLists.txt
file at the root of the project.