小编ant*_*009的帖子

编写Makefile时的最佳实践

gcc 4.4.2 c89

我写了这个Makefile.我想知道它是一个好的设计,易于维护吗?

我的事情,我想的是,cltsvr_ults.o获取与两个链接SVR_OBJECTSCLT_OBJECTS.这看起来是否正确?

非常感谢任何建议,

# ------------- SOURCE FILE ------------------------
SVR_OBJECTS = server.o cltsvr_ults.o test_svr.o
CLT_OBJECTS = client.o cltsvr_ults.o test_clt.o

# ------------- COMPILER OPTIONS -------------------
CFLAGS = -ggdb -Wall -pthread -std=c89 
CC = gcc
PLATFORM = -DLINUX
LIBS = -lpthread

# ------------- TARGETS ----------------------------
all: svr clt

svr: $(SVR_OBJECTS)
    $(CC) $(CFLAGS) $(PLATFORM) $(SVR_OBJECTS) -o svr

clt: $(CLT_OBJECTS)
    $(CC) $(CFLAGS) $(PLATFORM) $(CLT_OBJECTS) -o clt

clean:
    rm -f clt svr *.o *~

# -------------- DEPENDENCIES …
Run Code Online (Sandbox Code Playgroud)

makefile

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

链接apache库

gcc 4.4.2

我已经安装了apache runtime portable.APR-1.3.9

./configure
make
make test
make install
Run Code Online (Sandbox Code Playgroud)

一切安装都很好.

我的/usr/local/apr/lib所有库和包含在下面/usr/local/apr/include/apr-1

我有一个简单的main.c程序来测试:

#include <stdio.h>
#include <apr.h>

int main(void)
{
    printf(" == Start of program ==\n");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的makefile:

OBJECT_FILES = main.o

CC = gcc
CFLAGS = -Wall -g -D_LARGEFILE64_SOURCE

LIBS_PATH = -L/usr/local/apr/lib
INC_PATH = -I/usr/local/apr/include/apr-1

LIBS = -lapr-1

test_apr: $(OBJECT_FILES)
    $(CC) $(CFLAGS) $(OBJECT_FILES) $(LIBS_PATH) $(INC_PATH) $(LIBS) -o test_apr

main.o: main.c
    $(CC) -c $(CFLAGS) $(INC_PATH) $(LIBS_PATH) $(INC_PATH) main.c  
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试编译时,我收到以下错误:

gcc -c -I/usr/local/apr/include/apr-1 -L/usr/local/apr/lib -I/usr/local/apr/include/apr-1 main.c …
Run Code Online (Sandbox Code Playgroud)

c

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

创建类似函数的宏

gcc 4.4.2 c89

我有这个代码片段,我必须在很多代码中重复.我只是想知道有没有办法通过使用宏功能来缩短它?

有我想改变的代码.

ERR_INFO error_info; /* create error object */
ErrorInfo(&error_info); /* pass the address for it to be filled with error info */
fprintf(stderr, "And the error is? [ %s ]\n", error_info.msg); /* display the error msg */
Run Code Online (Sandbox Code Playgroud)

我试图创建一个宏功能来使用它.

#define DISPLAY_ERR(error_info) ErrorInfo(&error_info) error_info.msg
fprintf(stderr, "And the error is? [ %s ]\n", DISPLAY_ERR); /* display the error
Run Code Online (Sandbox Code Playgroud)

任何建议都会有所帮助,

c

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

重新调整普查员

gcc 4.1.2 c99

我在这个文件ccsmd.h中有以下枚举:

enum options_e
{
    acm = 0,
    anm,
    smd,
    LAST_ENTRY,

    ENTRY_COUNT = LAST_ENTRY
};

enum function_mode_e
{
    play = 0,
    record,
    bridge,
    LAST_ENTRY,

    ENTRY_COUNT = LAST_ENTRY
};
Run Code Online (Sandbox Code Playgroud)

错误消息:

error: redeclaration of enumerator ‘LAST_ENTRY’
error: previous definition of ‘LAST_ENTRY’ was here
error: redeclaration of enumerator ‘ENTRY_COUNT’
error: previous definition of ‘ENTRY_COUNT’ was here
Run Code Online (Sandbox Code Playgroud)

我有,LAST_ENTRY所以我可以使用它作为数组的索引.所以我喜欢在所有枚举中保持相同.

c

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

char数组的指针数组

gcc 4.4.4 c89

但是,我在尝试显示所有动物时遇到问题.

我有以下代码.

我正在尝试显示阵列中的所有动物.所以我有三个指向char*的指针数组.然后是指向这些数据集的指针数组.

我试图控制内循环以检查外部的-1和NULL.

void initialize_char_array()
{
    char *data_set1[] = {"dog", "cat", "bee", NULL};
    char *data_set2[] = {"rabbit", "ant", "snake", "rat", NULL};
    char *data_set3[] = {"cow", "lizard", "beaver", "bat", "hedgehog", NULL};

    char *ptr_char[] = {*data_set1, *data_set2, *data_set3, NULL};

    display_char_array(ptr_char);
}

void display_char_array(char **ptr_char)
{
    size_t inner = 0, outer = 0;

    for(outer = 0; ptr_char[outer] != NULL; outer++) {
        for(inner = 0; *ptr_char[inner] != -1; inner++) {
            printf("data [ %s ]\n", ptr_char[outer][inner]);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

非常感谢任何建议,

c pointers

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

使用time和difftime创建超时

gcc (GCC) 4.6.0 20110419 (Red Hat 4.6.0-5)
Run Code Online (Sandbox Code Playgroud)

我正在努力获得开始和结束时间.并获得它们之间的差异.

我的功能是为现有硬件创建API.

API wait_events采用一个以毫秒为单位的时间参数.所以我想在while循环之前开始.并使用时间来获得秒数.然后在循环的1次迭代之后获得时间差,然后将该差异与超时进行比较.

非常感谢任何建议,

/* Wait for an event up to a specified time out.
 * If an event occurs before the time out return 0
 * If an event timeouts out before an event return -1 */
int wait_events(int timeout_ms)
{
    time_t start = 0;
    time_t end = 0;
    double time_diff = 0;
    /* convert to seconds */
    int timeout = timeout_ms / 100;

    /* Get the initial time */
    start …
Run Code Online (Sandbox Code Playgroud)

c

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

非法开始学期

GNU Emacs 23.2.1 prolog-mode-version是`prolog.el'中定义的变量.它的值是"1.22"

我查阅过以下文件:

body(mercury, 36, small, none, none).
body(venus, 67, small, atmosphere, none).
body(earth, 93, small, atmosphere, none).
body(moon, 93, small, none, none).
body(mars, 141, small, atmosphere, none).
body(jupiter, 489, large, atmosphere, rings).
Run Code Online (Sandbox Code Playgroud)

但是,当我执行以下操作时:

body(Body, Miles, _, _, _,) , Miles > 100.
Run Code Online (Sandbox Code Playgroud)

我收到以下错误,对我来说似乎完全合法:

?- body(Body, Miles, _, _, _,) , Miles > 100.
ERROR: Syntax error: Illegal start of term
ERROR: body(Body, Miles, _, _, _,
ERROR: ** here **
ERROR: ) , Miles > 100 . …
Run Code Online (Sandbox Code Playgroud)

prolog

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

分配动态2D字符数组

gcc 4.6.2 c89

为2D阵列分配内存并填充字符.

但是,我似乎没有填写,因为我打印什么都没有显示.

我在这里做错了吗?

char **attributes = NULL;

/* TODO: Check for memory being allocated */
attributes = malloc(3 * sizeof(char*));
int i = 0;
int k = 0;

for(i = 0; i < 3; i++) {
    for(k = 0; k < 5; k++) {
        sdp_attributes[i] = malloc(5 * sizeof(char));
        sdp_attributes[i][k] = k;
    }
}

for(i = 0; i < 3; i++) {
    for(k = 0; k < 5; k++) {
        printf("attributes[i][k] [ %c ]\n", attributes[i][k]);
    }
} …
Run Code Online (Sandbox Code Playgroud)

c memory-management multidimensional-array

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

在if-else语句中使用范围(..)

python 2.7

是否有可能做到这一点:

print "Enter a number between 1 and 10:"
number = raw_input("> ")

if number in range(1, 5):
    print "You entered a number in the range of 1 to 5"
elif number in range(6, 10):
    print "You entered a number in the range of 6 to 10"
else:
    print "Your number wasn't in the correct range"
Run Code Online (Sandbox Code Playgroud)

我发现如果我将数字放在1到10之间,它总是属于else语句.

这是if-else语句中in range的错误使用吗?

提前谢谢了,

python

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

git不会获取新的更改

git version 1.7.11.4
3.5.3-1.fc17.x86_64 #1 SMP x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)

你好,

当我尝试从远程存储库中获取更改时,我输入密码,然后没有任何反应,提示只是返回.我从需要合并的遥控器进行了更改,但无法获取这些更改.这就是我所做的.

git remote show origin
resource_division pushes to resource_division (local out of date)
Run Code Online (Sandbox Code Playgroud)

当我尝试获取这些更改时,我什么也得不到:

$ git fetch origin
dev@10.10.10.18's password: 
$ 
Run Code Online (Sandbox Code Playgroud)

我已经做了以下尝试和清理:

git fsck
git clean -f
git gc
Run Code Online (Sandbox Code Playgroud)

这曾经工作,现在已经停止了.

非常感谢任何建议,

git

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