相关文章推荐

按照该教程 https://aquamentus.com/flex_bison.html 学习flex和bison时,遇到了如下问题

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libfl.so: undefined reference to `yylex'
collect2: error: ld returned 1 exit status

flex文件:

#include <cstdio> #include "snazzle.tab.h" // to get the token types from Bison //extern int yylex(); [ \t\n] ; [0-9]+\.[0-9]+ { yylval.fval = atof(yytext); return FLOAT; } [0-9]+ { yylval.ival = atoi(yytext); return INT; } [a-zA-Z0-9]+ { // We have to strdup yytext because Flex will change it for the next token. // Note that this memory must be freed somewhere, so that's why we call // free() above in the Bison section. (Aside: we use free() instead of // delete because strdup is a C function that uses malloc, not a C++ // function that uses new.) yylval.sval = strdup(yytext); return STRING;

bison文件:

#include <cstdio> #include <iostream> using namespace std; // Declare stuff from Flex that Bison needs to know about: extern int yylex(); extern int yyparse(); extern FILE *yyin; void yyerror(const char *s); // Bison fundamentally works by asking flex to get the next token, which it // returns as an object of type "yystype". Initially (by default), yystype // is merely a typedef of "int", but for non-trivial projects, tokens could // be of any arbitrary data type. So, to deal with that, the idea is to // override yystype's default typedef to be a C union instead. Unions can // hold all of the types of tokens that Flex could return, and this this means // we can return ints or floats or strings cleanly. Bison implements this // mechanism with the %union directive: %union { int ival; float fval; char *sval; // Define the "terminal symbol" token types I'm going to use (in CAPS // by convention), and associate each with a field of the %union: %token <ival> INT %token <fval> FLOAT %token <sval> STRING // This is the actual grammar that bison will parse, but for right now it's just // something silly to echo to the screen what bison gets from flex. We'll // make a real one shortly: snazzle: INT snazzle { cout << "bison found an int: " << $1 << endl; | FLOAT snazzle { cout << "bison found a float: " << $1 << endl; | STRING snazzle { cout << "bison found a string: " << $1 << endl; free($1); | INT { cout << "bison found an int: " << $1 << endl; | FLOAT { cout << "bison found a float: " << $1 << endl; | STRING { cout << "bison found a string: " << $1 << endl; free($1); int main(int, char**) { // Open a file handle to a particular file: FILE *myfile = fopen("a.snazzle.file", "r"); // Make sure it is valid: if (!myfile) { cout << "I can't open a.snazzle.file!" << endl; return -1; // Set Flex to read from it instead of defaulting to STDIN: yyin = myfile; // Parse through the input: yyparse(); void yyerror(const char *s) { cout << "EEK, parse error! Message: " << s << endl; // might as well halt now: exit(-1);

运行指令:

在flex文件中添加%option noyywrap,加入该语句之后,g++指令就不需要添加-lfl参数

(-lfl 是为了将flex库文件链接!)

修改后的flex文件如下:

#include <cstdio> #include "snazzle.tab.h" // to get the token types from Bison //extern int yylex(); %option noyywrap [ \t\n] ; [0-9]+\.[0-9]+ { yylval.fval = atof(yytext); return FLOAT; } [0-9]+ { yylval.ival = atoi(yytext); return INT; } [a-zA-Z0-9]+ { // We have to strdup yytext because Flex will change it for the next token. // Note that this memory must be freed somewhere, so that's why we call // free() above in the Bison section. (Aside: we use free() instead of // delete because strdup is a C function that uses malloc, not a C++ // function that uses new.) yylval.sval = strdup(yytext); return STRING;

修改后的运行指令如下:

按照该教程https://aquamentus.com/flex_bison.html学习flex和bison时,遇到了如下问题/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libfl.so: undefined reference to `yylex'collect2: error: ld returned 1 exit statusflex文件:%{ #include &lt;cstd
ubuntu18.04 , cuda10.0 编译darknet出现/usr/bin/ld: cannot find -lcuda cannot find -lcuda 意思是编译时未找到libcuda库。 首先查看Makefile这中cuda路径是否正确,即下面第四行lib路径 ifeq ($(GPU), 1) COMMON+= -DGPU -I/usr/local/cuda-10.0/include/ CFLAGS+= -DGPU LDFLAGS+= -L/usr/local/cuda-10.0/lib64 -lcuda -lcudart -lcublas -lcurand endif /usr/bin/ld: /tmp/ccV9xYuG.o: undefined reference to symbol '_ZN2cv6imreadERKSsi' /opt/opencv-4.4.0-build/lib64/libopencv_imgcodecs.so.4.4: error adding symbols: DSO missing from command line collect2: error: ld returned
<br />最近在Linux下编程发现一个诡异的现象,就是在链接一个静态库的时候总是报错,类似下面这样的错误: (.text+0x13): undefined reference to `func' <br />    关于undefined reference这样的问题,网上也有很多的说法,在此,我以详细地示例给出其中的各种原因说明以及解决方法,然后再给出我所遇到的与大家均不同的问题。<br />1.  链接时缺失了相关目标文件(.o)<br />    测试代码如下:<br /> gcc -o main main.c 编译错误提示: /usr/bin/ld: /tmp/cckwgwIa.o: undefined reference to symbol 'sin@@GLIBC_2.2.5' /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO mis
/usr/bin/ld: ../../../lib/libcnstream_va.so.6.1.0: undefined reference to `RGB24ToNV12' /usr/bin/ld: ../../../lib/libcnstream_va.so.6.1.0: undefined reference to `RAWToNV12' /usr/bin/ld: ../../../lib/libcnstream_va.so.6.1.0: un. target — 目标文件, 可以是Object File 也可以是可执行文件,还可也是标签Label(标签内容在“伪目标”章节); prerequisites—生成target所需的文件或目标;
具体报错信息如下: /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../lib/Scrt1.o: in function `_start': (.text+0x24): undefined reference to `main' 一开始看了很多博客都说是main函数写错了,但我的main函数是没写错的。 后来发现可能自己的makefile写的不对,需要让带有main函数的文件在makefile中第一个出现。
解决/usr/bin/ld: ../common/common.o: undefined reference to symbol ‘UI_new@@OPENSSL_1.0.0‘//lib/x86_6
R源码编译安装前言安装包下载依赖包下载安装编译R总结 一般尽可能的使用编译好的R,或者使用miniconda安装R。 但是使用conda安装一些R包时会遇到各种各样的错误,同时如果需要使用更高版本的R,源码编译则是最好选择。安装过程中不断出现的报错让人头疼,这里简要记录安装遇到的报错及解决,有参考网上其他教程,一并谢过。 常见过程一笔带过。 安装包下载 环境:CentOS release 6...
当前工程的需求是把调用了boost库的C++工程编译成为一个动态链接库以供Python调用,(boos 的使用过程也有些曲折,详细过程及模板伪代码请见本人的这篇博客: ),但是在调整完成wrapper.cc后,编译,报错提示 /usr/bin/ld: ../lib/libXXX.a(XXX.cc.o): relocation R_X86_64_PC32 against symbol `_ZN8planning4eudm31_LonSim
 
推荐文章