-1

I am running a C project in Visual Studio 2015 I have got these errors:

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

My files tree:

 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

First error and section of code:

        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

code:

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;

Second error and section of code:

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);
}

Third error and section of code:

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);
}

Fourth error and section of code:

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");
 }

So what should I do ?

My 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

edited 2 add a part of 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));
}

edited 3 add f90.y edited 4 deleted f90.yas not related to the discution

John Crone
  • 34
  • 1
  • 7
  • you are not "running a project". You are receiving linker errors, so you have not gotten to running it yet. – Mike Nakis Jul 22 '17 at 13:15
  • Does a rebuild show any other errors? – alk Jul 23 '17 at 07:40
  • @alk no only those errors. – John Crone Jul 23 '17 at 22:45
  • Do you have this file `f90.tab.c`? – alk Jul 25 '17 at 12:21
  • Dear @alk no,I don't have .I think it's related to flex-bison.I want to know what's that and what's the usage.is it related to yyparse or finclude LNK errors? How to made that,please introduce me a link.please describe more. – John Crone Jul 25 '17 at 19:44
  • Very, yery brief: Bison creates `f90.tab.c` out of `f90.y`. Bison is the GNU clone of Yacc. Flex is the GNU clone of Lex. Both were written for UNIX-like systems. For a Windows port you want to deep dive in here http://gnuwin32.sourceforge.net/packages/bison.htm – alk Jul 26 '17 at 04:48
  • I want to disable lnk error for `finclude` in `.lex` file.does this satisfy that purpose?another question is that I want disable LNK error for `yyparse` .is there any way. Brief description please. – John Crone Jul 26 '17 at 12:00
  • Is this link helpful for `yyparse`,would you please give a brief description. https://stackoverflow.com/questions/23974637/unresolved-external-symbol-for-yyparse – John Crone Jul 26 '17 at 12:13
  • I updated my question as Edited 3 `f90.y` maybe helpful. – John Crone Jul 26 '17 at 14:05
  • You need to have `f90.tab.c`. Bison would create it for you (as clearly shown by the `Makefile`. Where to get and how to install and run it should all be in the link I gave in my last comment. – alk Jul 26 '17 at 14:49
  • Dear @alk does your last comment http://gnuwin32.sourceforge.net/packages/bison.htm work with visual studio 2015? – John Crone Jul 26 '17 at 16:19
  • You most likley need to run it seperatly. – alk Jul 26 '17 at 16:23
  • I run `bison -dy f90.y` and now I have `y.tab.c` so what should I do next? – John Crone Jul 26 '17 at 18:15
  • i used the instruction as https://stackoverflow.com/questions/5456011/how-to-compile-lex-yacc-files-on-windows – John Crone Jul 26 '17 at 18:29

2 Answers2

0

The errors are not in the code that you are showing us. The errors are either in the header files that you are including, (functions declared as something other than _cdecl, so their names do not begin with underscores,) or in your makefile / project file (you are simply not linking the object files generated from the .c files that declare the functions that you are invoking.)

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
  • This is a comment, not an answer. – too honest for this site Jul 22 '17 at 13:31
  • 1
    @Olaf No, it is an answer. It lists the two possible places to look for the problem, and it is useful for anyone who might view this question in the future even if the question does not get updated to include more information. – Mike Nakis Jul 22 '17 at 13:40
  • error problems 3th and 4th solved as I changed `strcasecmp` to `stricmp`. but still have errors with `yyparse` and `finclude`in 1th and 2th error problems. – John Crone Jul 23 '17 at 23:37
  • for `finclude` I updated my question add a part of `f90.lex` file.but I don't know how to behave with that command and lex file. – John Crone Jul 24 '17 at 02:27
0

My problem solved as I follow instruction in How to compile LEX/YACC files on Windows?

and use this project http://www.ncsa.illinois.edu/People/mdewing/f90toC/ and make the project in command prompt.Not Visual Studio 2015 environment so I use ff90.exe to compile fortran .f90 files to .c files as the instruction mentioned .but the ff90.exe is not really strong and take errors in such tests.this is related to the developer.

John Crone
  • 34
  • 1
  • 7