gpt4 book ai didi

c - 在 Visual Studio 2015 中运行 C 项目时出现错误 LNK1120 3 无法解析的外部

转载 作者:行者123 更新时间:2023-11-30 19:33:36 25 4
gpt4 key购买 nike

我正在 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,因为与讨论无关

最佳答案

错误不在您向我们展示的代码中。这些错误要么出现在您所包含的头文件中(函数声明为 _cdecl 以外的内容,因此它们的名称不以下划线开头),要么出现在您的 makefile/项目文件中(您只需不链接从声明您正在调用的函数的 .c 文件生成的目标文件。)

关于c - 在 Visual Studio 2015 中运行 C 项目时出现错误 LNK1120 3 无法解析的外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45254870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com