我有一个Makefile,我已经复制并使用在许多我用C语言为Linux编写的小程序中。遗憾的是,我并不理解它是如何工作的每个细节,我通常只是注释掉输出文件的名称并插入我想要的名称,它成功地编译了我的程序。我想使用以下说明:
拥有命令行编译器的通常使用'/I%SQLAPIDIR%\include‘或'-I${SQLAPIDIR}/include’等选项。头文件位于SQLAPI++发行版的包含子目录中。
这样,我的Makefile在编译时将添加库。我查看了这个网站并找到了以下链接,但它们没有帮助:
What are the GCC default include directories?
how to add a new files to existing makefile project
我试图包括目录..。
OBJS = testql.o
CC = g++
DEBUG = -g
SQLAPI=/home/developer/Desktop/ARC_DEVELOPER/user123/testsql/SQLAPI
CFLAGS = -I${SQLAPI}/include -Wall -c $(DEBUG)
LFLAGS = -Wall $(DEBUG)
testql: $(OBJS)
$(CC) $(LFLAGS) $(OBJS) -o testql
clean:
rm -f testql *.o *~ core当我运行下面的代码时,会得到以下错误:
[developer@localhost testql]$ make
g++ -c -o testql.o testql.cpp
testql.cpp:2:44: fatal error: SQLAPI.h: No such file or directory
#include <SQLAPI.h> // main SQLAPI++ header该目录如下:
[developer@localhost testql]$ ls -l
total 12
-rw-rw-r--. 1 developer developer 286 Mar 3 12:47 Makefile
drwxr-xr-x. 7 developer developer 4096 Oct 16 02:08 SQLAPI
-rw-rw-r--. 1 developer developer 1169 Mar 3 11:43 testql.cppSQLAPI目录是这样的:
[developer@localhost testql]$ ls SQLAPI/include/SQLAPI.h
SQLAPI/include/SQLAPI.h密码..。
#include <stdio.h> // for printf
#include <SQLAPI.h> // main SQLAPI++ header
int main(int argc, char* argv[])
{
SAConnection con; // create connection object
try
{
// connect to database
// in this example it is Oracle,
// but can also be Sybase, Informix, DB2
// SQLServer, InterBase, SQLBase and ODBC
con.Connect(
"test", // database name
"tester", // user name
"tester", // password
SA_Oracle_Client);
printf("We are connected!\n");
// Disconnect is optional
// autodisconnect will ocur in destructor if needed
con.Disconnect();
printf("We are disconnected!\n");
}
catch(SAException &x)
{
// SAConnection::Rollback()
// can also throw an exception
// (if a network error for example),
// we will be ready
try
{
// on error rollback changes
con.Rollback();
}
catch(SAException &)
{
}
// print error message
printf("%s\n", (const char*)x.ErrText());
}
return 0;
}发布于 2015-03-03 18:20:57
很明显,如果您查看编译行,它调用的是:
g++ -c -o testql.o testql.cpp这里没有-I标志。问题是,CFLAGS变量用于编译C代码,但您正在编译C++代码。如果要设置特定于C++编译器的标志,则需要设置CXXFLAGS。
但是,对于所有的预处理器标志,您应该使用CPPFLAGS;C和C++编译器(以及调用预处理器的其他工具)都会使用这一标记。因此,请使用:
CPPFLAGS = -I${SQLAPI}/include
CFLAGS = -Wall $(DEBUG)
CXXFLAGS = $(CFLAGS)发布于 2015-03-03 17:30:28
定义变量SQLAPI,使其值为安装SQLAPI的目录。
然后使用变量定义CFLAGS。
SQLAPI=/directory/where/sqlapi/is/installed
CFLAGS = -I${SQLAPI}/include -Wall -c $(DEBUG)发布于 2020-06-29 12:31:57
在您的MakeFile中,修改CMAKE_CXX_FLAGS如下:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/path/to/your/folder")https://stackoverflow.com/questions/28838079
复制相似问题