我在Visual Studio 2015中运行C项目我遇到了这些错误:
Severity Code Description Project File Line
Error LNK1120 3 unresolved externals f90toC_B C:\Users\admin\Documents\Visual Studio 2015\Projects\f90toC_B\Debug\f90toC_B.exe 1
Error LNK2019 unresolved external symbol _yyparse referenced in function _main f90toC_B C:\Users\admin\Documents\Visual Studio 2015\Projects\f90toC_B\f90toC_B\f90main.obj 1
Error LNK2019 unresolved external symbol _finclude referenced in function _getMfile f90toC_B C:\Users\admin\Documents\Visual Studio 2015\Projects\f90toC_B\f90toC_B\f90mod.obj 1
Error LNK2019 unresolved external symbol _strcasecmp referenced in function _findarg f90toC_B C:\Users\admin\Documents\Visual Studio 2015\Projects\f90toC_B\f90toC_B\ptree.obj 1
Error LNK2001 unresolved external symbol _strcasecmp f90toC_B C:\Users\admin\Documents\Visual Studio 2015\Projects\f90toC_B\f90toC_B\symb.obj 1
我的文件树:
C:.
│ f90.h
│ f90.lex
│ f90.y
│ f90arg.c
│ f90arg.h
│ f90arg.o
│ f90decl.c
│ f90decl.h
│ f90decl.o
│ f90main.c
│ f90main.h
│ f90main.o
│ f90mod.c
│ f90mod.h
│ f90print.c
│ File_index
│ Makefile
│ ptree.c
│ ptree.h
│ README
│ symb.c
│ symb.h
│
├───doc
│ description.txt
│
└───tests
Makefile
mtest1.f90
mtest1.M.std
mtest1.std
test1.f90
test1.std
test2.f90
test2.std
test3.f90
test3.std
第一个错误和代码部分:
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol _yyparse referenced in function _main f90toC_B C:\Users\admin\Documents\Visual Studio 2015\Projects\f90toC_B\f90toC_B\f90main.obj 1
代码:
f90main.c
#include "f90.h"
#include "ptree.h"
#include "symb.h"
#include "f90main.h"
#include "f90decl.h"
#include "f90arg.h"
main()
{
yyparse();
}
int lineno=1;
extern struct declist *declisthead;
extern int in_module;
第二个错误和代码部分:
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol _finclude referenced in function _getMfile f90toC_B C:\Users\admin\Documents\Visual Studio 2015\Projects\f90toC_B\f90toC_B\f90mod.obj 1
f90mod.c
/* handles things related to modules */
#include "symb.h"
#include "ptree.h"
#include "f90mod.h"
#include <stdio.h>
struct declist *modlist=NULL;
int doing_module=0;
int in_module=0;
int in_user_type=0;
char *curr_modname=NULL;
struct declist *modsubshead=NULL;
void getMfile(char *nam)
{
char name[35];
modlist=newdeclist(TBLANK,nam,modlist,NULL);
curr_modname=modlist->name;
doing_module=1;
strcpy(name,nam);
strcpy(name+strlen(name),".M");
/*fprintf(stderr,"mod name: %s\n",name);*/
finclude(name);
}
第三个错误和代码部分:
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol _strcasecmp referenced in function _findarg f90toC_B C:\Users\admin\Documents\Visual Studio 2015\Projects\f90toC_B\f90toC_B\ptree.obj 1
ptree.c
/* finds a keyword based argument with name "name" */
struct tree *findarg(struct tree *t, char *name)
{
struct tree *t1;
if (t==NULL) return(NULL);
if (t->ntype==ALISTNODE) {
if ( (t1=findarg(t->child1,name)) != NULL) return(t1);
if (t->child2->ntype == ARGKWNODE) {
if (strcasecmp(t->child2->child1->num.s,name)==0) {
return (t);
} else {
return(NULL);
}
}
} else {
fprintf(stderr,"Do I ever get here in findarg?\n");
}
return(NULL);
}
第四个错误和代码部分:
Severity Code Description Project File Line
Error LNK2001 unresolved external symbol _strcasecmp f90toC_B C:\Users\admin\Documents\Visual Studio 2015\Projects\f90toC_B\f90toC_B\symb.obj 1
symb.c
int findsymbt(struct declist *d,char *s)
{
int f;
if (d==NULL) return(0);
/*printf("symb: ntype %d name %s\n",d->ntype,d->name);*/
if (d->ntype==TSEQ) {
if ( (f=findsymbt(d->next,s))!=0 ) {return(f);}
f=findsymbt(d->next2,s);
return(f);
} else {
if ((f=strcasecmp(d->name,s))==0) {return (d->ntype);}
else {return (0);}
}
printf("I shouldn't be here \n");
}
那我该怎么办?
我的Makefile
CC = cc -ggdb
OBJ = f90main.o f90decl.o f90arg.o f90.tab.o lex.yy.o symb.o ptree.o \
f90mod.o f90print.o
.c.o:
$(CC) -c $<
all: f90
lex.yy.c: f90.lex
flex -i f90.lex
f90.tab.c: f90.y f90.h
bison -d f90.y
f90: $(OBJ) f90.h
$(CC) -o ff90 $(OBJ)
why:
bison -d -v f90.y
clean:
-rm *.o lex.yy.c f90.tab.c f90.tab.h f90.output
F = f90toC
tar:
tar -cvf f90toC-test.tar $(F)/f90.lex $(F)/f90.y $(F)/*.h $(F)/*.c $(F)/tests $(F)/doc $(F)/Makefile $(F)/README $(F)/File_index
bak:
cp *.c backup
cp *.h backup
cp *.y backup
cp *.lex backup
cp Makefile backup
编辑2添加f90.lex
...
finclude(char *text){
if (include_stack_ptr >= MAX_INCLUDE_BUFF) {
fprintf(stderr,"Includes nested too deep\n");
exit(1);
}
lineno_stack[include_stack_ptr] = lineno; lineno=1;
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
yyin = fopen(text,"r");
if (!yyin) {fprintf(stderr,"Failed to include:%s\n",text);
include_stack_ptr--;
return;}
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
}
已编辑3添加f90.y
编辑了4个已删除的f90.y
与讨论无关
答案 0 :(得分:0)
错误不在您向我们展示的代码中。错误在您包含的头文件中(声明为_cdecl
以外的函数,因此它们的名称不以下划线开头,)或在您的makefile /项目文件中(您只是不链接从声明要调用的函数的.c
文件生成的目标文件。)
答案 1 :(得分:0)
我按照How to compile LEX/YACC files on Windows?
中的说明解决了我的问题并使用此项目http://www.ncsa.illinois.edu/People/mdewing/f90toC/
和make
项目在命令提示符下。Not Visual Studio 2015 environment
所以我使用ff90.exe
将fortran .f90
文件编译为.c
文件,如上所述。但是ff90.exe并不是很强大,并且在这些测试中会出错。这与显影剂。