小编Tom*_*Tom的帖子

如何使用 C 源代码的 Makefile 创建静态库

我想了解如何创建 Makefile。我有以下 Makefile:

DESTDIR=../../
PREFIX=../

STATIC=libdemo.a

CC = gcc
CFLAGS = -Wall -Winline -pipe

LDFLAGS = -L../../../lib
LIBS    = -lpthread 

SRC = demo1.c demo2.c

OBJ = $(SRC:.c=.o)

$(STATIC): $(OBJ)
        @echo "[Link (Static)]"
        @ar rcs $(STATIC) $(OBJ)

.c.o:
        @echo [Compile] $<
        @$(CC) -c $(CFLAGS) $< -o $@

clean:
        rm -f $(OBJ) *~ core tags *.bak Makefile.bak libgeniePi.*

.PHONEY:        install
install:        $(TARGET)
        @install -m 0755 libdemo.a  $(DESTDIR)$(PREFIX)/lib

all:
        gcc -g -Wall -o program program.c $(LDFLAGS) $(LIBS)
Run Code Online (Sandbox Code Playgroud)

这几乎符合我想要的。我从make文件 demo1.cdemo2.c …

c makefile

2
推荐指数
1
解决办法
1万
查看次数

在C中的Windows机器上进行开发时,为什么会出现include <windows.h>错误?

我是C的新手,我正在尝试编译使用外部库的代码.因此,我按照这些步骤链接库.但是在第一个

gcc -c -Wall -Werror -fpic PICASO_SERIAL_4DLIBRARY.C
Run Code Online (Sandbox Code Playgroud)

我明白了

PICASO_SERIAL_4DLIBRARY.C:1:0: error: -fpic ignored for target (all code is position independent) [-Werror]
#include <windows.h>


cc1plus.exe: all warning being treated as errors
Run Code Online (Sandbox Code Playgroud)

另外,#上面有一个箭头.我试着用搜索引擎,但我只能发现这是一个Linux的问题,不是Windows一个(我开发在Windows现在)和我跟着这些步骤来安装gcc.编制其他小项目也是有效的.

任何人都知道,为什么这不起作用?

c windows gcc

1
推荐指数
1
解决办法
502
查看次数

JSON的正确语言是什么

我有一个名为的JSON文件myjson.cfg,如下所示:

{    
        "values": {
            "a": 1,
            "b": 2,
            "c": 3,
            "d": 4
        },
    "sales": [
        { "a": 0, "b": 0, "c": 0, "d": 0, "e": "karl" },
        { "a": 0, "b": 0, "c": 0, "d": 0, "e": "karl" }
    ]
}
Run Code Online (Sandbox Code Playgroud)

在我的HTML中,我包括这样的文件: <script type='text/javascript' src="myjson.cfg' "></script>

但是,我得到了一个

未捕获的SyntaxError:意外的令牌:

第二行中的错误就是这个错误

"values": {

为什么?当我看这个例子时,它看起来和我很相似?!

提前致谢 !

javascript json syntax-error

1
推荐指数
1
解决办法
59
查看次数

返回时double变为舍入

如何在没有舍入的情况下返回双精度数:

int function() {
    double d = 5.894; 
    printf("d=%f\n", d);
    return d;
}

int main() {
    double d = function();
    printf("d=%f\n", d);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这给了我

d=5.894000
d=5.000000
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?

c double return return-value

-1
推荐指数
1
解决办法
52
查看次数

标签 统计

c ×3

double ×1

gcc ×1

javascript ×1

json ×1

makefile ×1

return ×1

return-value ×1

syntax-error ×1

windows ×1