我是 osx 的新手,我遇到了一些问题。我尝试生成文件,但提出了:
error: unknown type name 'u_char'; did you mean 'char'?
我提到 C PCAP 库未知类型错误,将-D_BSD_SOURCECFLAGS添加到我的 makefile,但它没有帮助。我错过了什么?
编辑:
这是产生错误的代码:
char *computePwd(const u_char *md5) {
static char buf[16];
unsigned char tmp[40];
int tmpl=0;
tmpl = strlen(userName);
strcpy((char*)tmp, userName);
memcpy(tmp + tmpl, md5, 16);
tmpl += 16;
memcpy(buf, ComputeHash(tmp, tmpl), 16);
memset(tmp, 0, 16);
strcpy((char*)tmp, password);
int i;
for (i=0; i<16; ++i)
buf[i] ^= tmp[i];
return buf;
}
Run Code Online (Sandbox Code Playgroud) GNU make 有以下选项可以避免重新编译:
-o file, --old-file=file, --assume-old=file
Do not remake the file file even if it is older than its dependen?
cies, and do not remake anything on account of changes in file.
Essentially the file is treated as very old and its rules are
ignored.
Run Code Online (Sandbox Code Playgroud)
所以给出以下内容Makefile:
A : B
touch A
B : C
touch B
C :
touch C
Run Code Online (Sandbox Code Playgroud)
假设所有文件在某个时候都存在,我可以运行以下命令:
$ touch C
$ make A -o B
make: `A' is up to date. …Run Code Online (Sandbox Code Playgroud) 我正在使用 CMake 构建一个测试可执行文件。在构建过程中,我想运行可执行文件,它返回测试是否通过。如果没有,我希望构建失败。但是,当我使用add_custom_command(... POST_BUILD ... ), 并使用Makefile生成器时,测试可执行文件将被删除(在这个问题中解释:Why does GNU make delete a file)。
有没有办法让 CMake 将可执行文件视为.PRECIOUS,或者以其他方式更改 CMakeLists.txt 以便在测试失败时不会删除可执行文件?
作为参考,我的 CMakeList.txt 如下所示(从实际简化):
add_executable(UnitTest unittest.cpp)
add_custom_command(TARGET UnitTest POST_BUILD COMMAND $<TARGET_FILE:UnitTest>)
Run Code Online (Sandbox Code Playgroud) 我尝试构建gitql。
我已经安装了 go、CMake 和 MinGW,并试图让它们在 git bash 下工作,但是当我在 gitql 目录中调用 cmake 时,出现此错误:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:14 (PROJECT):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. …Run Code Online (Sandbox Code Playgroud) HOMEDIR = $(shell pwd)
DEFAULT = 4.0.3
YESDIR = $(shell echo $(@:install-%=%) | tr A-Z a-z)
NODIR = $(shell echo $(@:clean-%=%) | tr A-Z a-z)
install:
@$(MAKE) install-$(DEFAULT)
install-%:
@cd $(HOMEDIR);\
if [ ! -e $(YESDIR) ]; then \
echo "Library $(@:install-%=%) Version=$(YESDIR) does not exist"; \
elif [ -e $(YESDIR)/Install.sh ]; then \
echo "Installing $(PKGNAM) version=$(YESDIR)" ; \
cd $(YESDIR) ;\
$(SHELL) Install.sh $(HOMEDIR) 1 ;\
elif [ -e $(YESDIR)/Makefile ]; then \
cd $(YESDIR); \
$(MAKE); \ …Run Code Online (Sandbox Code Playgroud) Make是否应该始终重新制作具有先决条件但不指向文件且没有配方的目标?或者,如果需要重新制作一个或多个先决条件,Make应该只重新制作此类目标吗?
例如,在下面显示的 Makefile 中,我添加了一个名为的目标objects,该目标具有先决条件,但不指向文件。调用主要目标program取决于objects(以及可能的其他先决条件)。
file1 file2 file3: ; touch $@
objects: file1 file2
program: objects file3 ; @echo 'Making $@'
Run Code Online (Sandbox Code Playgroud)
我的期望是,何时make program运行并且不需要重新制作文件先决条件(即文件 1、文件 2 和文件 3 都存在),program不应重新制作。
然而,实际的 GNU Make行为是program始终运行的配方(无论先决条件文件如何)。这是因为objects总是被认为是重新制作的,这会强制重新制作任何依赖项(即program)。
您可以通过运行来验证这一点:make --trace -d --no-builtin-rules program并且您会看到Make总是输出“ Must remake target 'objects'。 ” Soobjects总是“remade”(即使它没有配方)并且它总是被认为是新更新的。
这很可能是因为objects不指向真实文件。但我期待因为它没有配方,只要不需要重新制作它的先决条件,它就不会被重新制作。
这是预期的行为还是错误?
在GNU进行手动状态:
如果规则没有先决条件或配方,并且规则的目标是一个不存在的文件,则 make 会认为该目标在其规则运行时已更新。这意味着依赖于该目标的所有目标将始终运行其配方。
但该描述不适用于上述情况,因为objects目标 …
make可以将变量赋值作为命令行的一部分。是DEBUG=1 make一样的make DEBUG=1吗?使用这个简单的 Makefile,两者都打印echo 1.
$ cat Makefile
all:
echo ${DEBUG}
Run Code Online (Sandbox Code Playgroud)
很明显,在后一种情况下,DEBUG=1是 的参数的一部分make,但第一个似乎只是 shell 中的变量赋值。所以我假设make以不同的方式获得价值。对差异进行一些澄清会有所帮助。
每当我构建我的包时,它都会使用/usr/bin/g++(系统编译器)。我想用 C++11 构造构建我的包。我试过-std=c++11选项,但系统编译器显示无法识别的选项。我想从不同的gcc编译器构建我的包,该编译器将作为我的包依赖项的一部分下载。
那么,如何gcc在 Makefile 中指定编译器的位置?
首先Makefile这里有
CFLAGS = -g -Wall -lm
Run Code Online (Sandbox Code Playgroud)
C那个时候我在玩。现在我开始了C++,我必须添加-I eigen,快速 google 上它并发现CXXFLAGS为C++世界而CFLAGS存在,而为C世界而存在。所以我更新Makefile到
CFLAGS = -g -Wall -lm
CXXFLAGS = -I eigen
Run Code Online (Sandbox Code Playgroud)
然后我找到了https://wiki.gentoo.org/wiki/GCC_optimization,受到启发再次更新
CFLAGS = -g -Wall -lm
CXXFLAGS = ${CFLAGS} -I eigen
Run Code Online (Sandbox Code Playgroud)
完整的东西:
CC = g++
CFLAGS = -g -Wall -lm
CXXFLAGS = ${CFLAGS} -I eigen
OBJS = main.o multiply.o
PROGRAM = multitply
$(PROGRAM): $(OBJS)
$(CC) $(OBJS) $(CFLAGS) -o $(PROGRAM)
Run Code Online (Sandbox Code Playgroud)
我要补充-I eigen …
我有许多设备驱动程序:每个设备的源代码都在一个与设备同名的子目录中:
devices/foo/foo.c
devices/bar/bar.c
Run Code Online (Sandbox Code Playgroud)
如果我像这样为每个设备设置单独的 GNU make 规则,它会起作用:
obj/foo.o: devices/foo/foo.c
$(CC) $(CFLAGS) devices/foo/foo.c -o obj/foo.o
Run Code Online (Sandbox Code Playgroud)
如果我设置了这样的制作模式,则无法确定如何制作文件。我猜这个问题与使用 % 作为子目录的名称有关。
obj/%.o: devices/%/%.c
$(CC) $(CFLAGS) $< -o $@
Run Code Online (Sandbox Code Playgroud)
有什么方法可以设置一个模式来做到这一点?