ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

linux-无法使用g进行编译

2019-10-31 16:50:32  阅读:255  来源: 互联网

标签:gcc g gaul linux compilation


现在,我尝试使用一种名为“ GAUL”的开源工具,其中实现了一些遗传算法.通过编译示例文件,我发现只能使用gcc来编译这些数据,而不能使用g来编译. E.x .:

1)使用gcc -I /usr/local/include / -c wildfire_threat.c -o test.o

gcc ** -g -O2 -Wall -o test2.out test.o -lgaul -lgaul_util -lm -lpthread -lslang -lm

也可以组合

gcc -I /usr/local/include / -c wildfire_threat.c -o test.o

g -g -O2 -Wall -o test2.out test.o -lgaul -lgaul_util -lm -lpthread -lslang -lm

但是2)使用

g -I /usr/local/include / -c wildfire_threat.c -o test.o

g -g -O2 -Wall -o test2.out test.o -lgaul -lgaul_util -lm -lpthread -lslang -lm

我收到以下错误消息:

test.o: In function `wildfire_simulation(int*, bool)':
wildfire_threat.c:(.text+0x52): undefined reference to `random_int(unsigned int)'
wildfire_threat.c:(.text+0x74): undefined reference to `random_int(unsigned int)'
test.o: In function `wildfire_score(population_t*, entity_t*)':
wildfire_threat.c:(.text+0xb55): undefined reference to `ga_entity_set_fitness(entity_t*, double)'
test.o: In function `wildfire_seed(population_t*, entity_t*)':
wildfire_threat.c:(.text+0xb86): undefined reference to `random_boolean()'
wildfire_threat.c:(.text+0xbb9): undefined reference to `random_boolean_prob(double)'
wildfire_threat.c:(.text+0xc18): undefined reference to `random_int(unsigned int)'
wildfire_threat.c:(.text+0xc25): undefined reference to `random_int(unsigned int)'
wildfire_threat.c:(.text+0xc92): undefined reference to `random_int(unsigned int)'
test.o: In function `wildfire_mutate_flip(population_t*, entity_t*, entity_t*)': 
wildfire_threat.c:(.text+0xd41): undefined reference to `random_int(unsigned int)'
test.o: In function `wildfire_crossover(population_t*, entity_t*, entity_t*, entity_t*, entity_t*)':
wildfire_threat.c:(.text+0xe25): undefined reference to `random_boolean()' 
wildfire_threat.c:(.text+0xe37): undefined reference to `random_int(unsigned int)' 
wildfire_threat.c:(.text+0xff0): undefined reference to `random_int(unsigned int)'
test.o: In function `wildfire_ga_callback(int, population_t*)':
wildfire_threat.c:(.text+0x11bc): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x11c4): undefined reference to `ga_entity_get_fitness(entity_t*)'
wildfire_threat.c:(.text+0x11ef): undefined reference to 
`ga_population_score_and_sort(population_t*)' 
wildfire_threat.c:(.text+0x1206): undefined reference to `ga_fitness_mean_stddev(population_t*, double*, double*)'
wildfire_threat.c:(.text+0x122b): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1233): undefined reference to `ga_entity_get_fitness(entity_t*)'
wildfire_threat.c:(.text+0x1268): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1270): undefined reference to `ga_entity_get_fitness(entity_t*)'
test.o: In function `main':
wildfire_threat.c:(.text+0x12b0): undefined reference to `random_seed(unsigned int)'
wildfire_threat.c:(.text+0x12dd): undefined reference to `ga_select_two_roulette_rebased(population_t*, entity_t**, entity_t**)'
wildfire_threat.c:(.text+0x12e6): undefined reference to `ga_select_one_roulette_rebased(population_t*, entity_t**)'
wildfire_threat.c:(.text+0x132e): undefined reference to `ga_genesis_integer(int, int, int, bool (*)(int, population_t*), bool (*)(int, entity_t*), void (*)(void*), void (*)(void*), bool (*)(population_t*, entity_t*), bool (*)(population_t*, entity_t*), entity_t* (*)(population_t*, entity_t*), bool (*)(population_t*, entity_t**), bool (*)(population_t*, entity_t**, entity_t**), void (*)(population_t*, entity_t*, entity_t*), void (*)(population_t*, entity_t*, entity_t*, entity_t*, entity_t*), void (*)(population_t*, entity_t*), void*)'
wildfire_threat.c:(.text+0x135c): undefined reference to `ga_population_set_parameters(population_t*, ga_scheme_type_t, ga_elitism_type_t, double, double, double)'
wildfire_threat.c:(.text+0x136d): undefined reference to `ga_evolution_threaded(population_t*, int)'
wildfire_threat.c:(.text+0x137e): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1386): undefined reference to `ga_entity_get_fitness(entity_t*)'
wildfire_threat.c:(.text+0x13b5): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1434): undefined reference to `ga_get_entity_from_rank(population_t*, unsigned int)'
wildfire_threat.c:(.text+0x1528): undefined reference to `ga_extinction(population_t*)'
collect2: ld returned 1 exit status

谁能向我解释这个谜,以及如何避免使用gcc,因为这会给我想要嵌入的其余源代码带来问题?

解决方法:

您的第三方C库的标头中可能缺少extern“ C”声明.要解决此问题而无需修改第三方标头,则可以在C源代码中无论您在#include相关的第三方标头中执行以下操作:

extern "C" {
  #include "gaul.h"         // note: I'm just guessing the names of the
  #include "gaul_utils.h"   //       actual header files here...
}

标签:gcc,g,gaul,linux,compilation
来源: https://codeday.me/bug/20191031/1977198.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有