'How can I add a path to a Makefile?
In C++, I have a library path I know how include when building with a CMakeLists.txt file but I don't know how to include it when building with a Makefile.
I tried applying the solution asked and answered here but it didn't work. The contents of the Makefile is below. The library's name is "NumCpp". The full path to this library on my computer is C:\Users\ooo\tor\Robot\rainbow\NumCpp\include\.
In the .cc file I am including the library as #include "NumCpp.hpp"
This is the CMakeLists.txt file. This would include and compile the NumCpp library if you ran this in the directory containing NumCpp. I don't know if it is helpful to show this, but I know I can include the library this way.
cmake_minimum_required(VERSION 3.14)
project("HelloWorld" CXX)
add_executable(${PROJECT_NAME} main.cpp)
find_package(NumCpp 2.6.2 REQUIRED)
target_link_libraries(${PROJECT_NAME}
NumCpp::NumCpp
)
The Makefile. I tried using INC_DIR, CFLAGS, and DEPS to link the path to the library but I'm getting an error.
COMMON=/O2 /MT /EHsc /arch:AVX /I../include /Fe../bin/
cl_vars = 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\Hostx86\x86\cl.exe'
cl_var = 'cl'
INC_DIR = C:/Users/ooo/tor/Robot/rainbow/NumCpp/include/
CFLAGS=-c -Wall -I$(INC_DIR)
DEPS = NumCpp.hpp
all:
$(cl_var) $(COMMON) testxml.cc ../bin/mujoco210nogl.lib
$(cl_var) $(COMMON) testspeed.cc ../bin/mujoco210nogl.lib
$(cl_var) $(COMMON) compile.cc ../bin/mujoco210nogl.lib
$(cl_var) $(COMMON) derivative.cc /openmp ../bin/mujoco210nogl.lib
$(cl_var) $(COMMON) basic.cc ../bin/glfw3.lib ../bin/mujoco210.lib
$(cl_var) $(COMMON) record.cc ../bin/glfw3.lib ../bin/mujoco210.lib
$(cl_var) $(COMMON) simulate.cc ../include/uitools.c ../bin/glfw3.lib ../bin/mujoco210.lib
del *.obj
The error...
simulate.cc(14): fatal error C1083: Cannot open include file: 'NumCpp.hpp': No such file or directory
Generating Code...
Compiling...
uitools.c
Generating Code...
make: *** [Makefile:16: all] Error 2
Solution 1:[1]
This line assigns a value to a makefile variable named COMMON:
COMMON=/O2 /MT /EHsc /arch:AVX /I../include /Fe../bin/
this line assigns a value to a makefile variable name cl_var:
cl_var = 'cl'
These lines in the recipe use (or "expand") the variables cl_var and COMMON:
$(cl_var) $(COMMON) testxml.cc ../bin/mujoco210nogl.lib
(etc.)
Note that nowhere in your makefile do you ever use the variables cl_vars, CFLAGS, INC_DIR, or DEPS, so those variable assignments are basically no-ops: useless. They might as well not be there at all, they have no effect on your makefile.
If you want to add a new directory to the include path, then you have to add it to the COMMON variable, because that's the variable that will be used. Since you're using Visual C++, not a POSIX compiler like GCC or Clang, the syntax is /I<path>, not -I<path>.
So, you should try something like this:
INC_DIR = C:/Users/ooo/tor/Robot/rainbow/NumCpp/include/
COMMON = /O2 /MT /EHsc /arch:AVX /I../include /I$(INC_DIR) /Fe../bin/
If you need more orientation, you probably need to read at least the introduction to something like the GNU make user's manual to get yourself a basic understanding of what a makefile is and how it works. SO is not equipped to provide full-fledged tutorials.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MadScientist |
