Is there a good working tutorial on re2c + lemon? - lemon

I've tried a couple. And there is only a couple of tutorials in Google for re2c+lemon.
Currently for all examples I get similar bunch of errors like:
In file included from main.cpp:2:0:
parser.y:44:5: error: ‘yygotominor’ was not declared in this scope
A.int_value = B.int_value * C.int_value;
^
In file included from main.cpp:2:0:
parser.c:770:16: error: ‘YY_MAX_SHIFTREDUCE’ was not declared in this scope
if( yyact <= YY_MAX_SHIFTREDUCE ){
^
parser.c:771:15: error: ‘YY_MAX_SHIFT’ was not declared in this scope
if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
^
Where is it declared?
PS: don't post 10y old articles (even without code or if the code can't be compiled now). If you can - write an example here. If not - don't post links from Google.

This tutorial works for me:
Get re2c (see re2c install page for details http://re2c.org/install/install.html).
Get lemon: download tarball wget http://prdownloads.sourceforge.net/souptonuts/lemon_examples.tar.gz, extract and build (I had to add #include <stdlib.h> to many examples for malloc).
Clone github repo https://github.com/tokuhirom/re2c-lemon-tutorial : git clone https://github.com/tokuhirom/re2c-lemon-tutorial.git
Patch re2c-lemon-tutorial/Makefile to find lemon and re2c (if needed).
make, ./mycalc and enjoy (hit Ctrl+D to stop and emit result).
More re2c examples on re2c website: http://re2c.org, more lemon examples inside of lemon tarball.

Related

Cant' build OpenCV 3.2.0 (Mingw32)

I know... Another one of this... But no one else's error is the same as mine and I've been trying to build opencv with mingw32 for days now.
When building OpenCV with mingw the command mingw32-make fails at some point trying to compile sources\modules\ts\src\ts_gtest.cpp with error pic bellow:
I've tried following several tutorials, but none work cleanly and this is the best I could get stuff to work.
What I did:
Installed Mingw and added C:\Mingw\bin\ to PATH environment variable.
Installed CMake and added it too to PATH.
Extracted OpenCV to C:\ and created forlder C:\opencv\mingwBuild\
In CMake-GUI I define source folder as C:\opencv\sources\ and build folder as C:\opencv\mingwBuild\.
Hit Configure and select Mingw Makefiles, with 'Use default native compilers' (have also specified compilers explicitly and the result is the same.).
Hit Generate, which creates the Makefile.
I open C:\Mingw\msys\1.0\msys.bat to have a console with all variables loaded (have also tried directly from a simple cmd.exe, given that PATH is set for mingw, but I get the same error in compilation). Navigate to C:\opencv\mingwBuild\ and run mingw32-make.
And that's where the error shows up after a while. Any ideas?
Turns ou gTest was not compiling in Mingw for some reason.
As I don't intend to test my code (for now) I removed opencv_ts from instalation (by deselecting it in Cmake, after configuring and before generating).
Someone mentions, in the first link #Dan Masek refers, that GTest has this issue with type conversion under mingw. They say that you can edit ts_gtest.cpp to apply the correct conversion, according to error message. That may be a solution if you need this module.
Another comment in #Dan Masek's second link mentions that gcc's version 5 surpasses the issue, which version 4 has. So, getting a hold of such distro may also be a solution.
For me it seems to be fixed by applying this fix: https://github.com/msk-repo01/opencv/commit/9a1835ce6676836ce278d723da4ff55a8f900ff1
(Also see: https://github.com/opencv/opencv/issues/8105)
The fix basically replaces the "_RTL_CRITICAL_SECTION" by "_CRITICAL_SECTION" for MingW compilers in modules/ts/include/opencv2/ts/ts_gtest.h in the following way:
The lines
// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
struct _RTL_CRITICAL_SECTION;
(around line 723 in OpenCV 3.2.0 release from Dec. 2016) are replaced by
# if GTEST_OS_WINDOWS_MINGW
// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
// separate (equivalent) structs, instead of using typedef
typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# else
// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# endif
and
_RTL_CRITICAL_SECTION* critical_section_;
is replaced by
GTEST_CRITICAL_SECTION* critical_section_;

How to setup jpeglib with MS Visual C++ 2010 Express

I try to use the well known "jpeglib" now available in version 9.
Overview: I am a programming starter in C using MS Visual C++ 2010 Express and read a C-book finally. My goal is to compress a RGB(.bmp)-file into JPEG. So I downloaded the jpeglib (v9), read all the install and so on *.txt-files. It was possible to compile the C-files to get cjpeg.exe, djpeg.exe, jpeg.lib and so on.
After this success I tried to use the example.c to get deeper into the jpeg and to control the compression. -> It did not work. Then I tried to use the jpeglib included in OpenCV. Same non working result, while the OpenCV code samples are compiled successfully.
I googled lots of samples, problem solutions and tips how to use jpeglib. Most helpful information I found here. But in the result I was still not able to compile my own jpeg-tool or example.c (rewriting the write_JPEG_file() function ).
Question: What in the basics could be wrong, when every other programmer just uses #include "jpeglib.h" in their codes to run the jpeg functions successfully? For me including this file seems not to be enough. Because of that I have to ask you and to relaunch a one year old Question that also did not helped solving my probs. I can not give you a specific error message because of multiple attempts to solve those issues.
Here is my current MS-VC++2010 config for using OpenCV 2.4.6:
C/C++ -> General -> Additional Include Directories:
C:\opencv\build\include
C:\opencv\build\include\opencv
C:\opencv\build\include\opencv2
C:\opencv\include
C:\opencv\include\opencv
C:\opencv\include\opencv2
C:\opencv\3rdparty\libjpeg
Linker -> General -> Additional Library Directories:
C:\opencv\build\x86\vc10\lib
Linker -> Input -> Additional Dependencies:
opencv_core246d.lib
opencv_imgproc246d.lib
opencv_highgui246d.lib
opencv_ml246d.lib
opencv_video246d.lib
opencv_features2d246d.lib
opencv_calib3d246d.lib
opencv_objdetect246d.lib
opencv_contrib246d.lib
opencv_legacy246d.lib
opencv_flann246d.lib
jpeg.lib [this I added into C:\opencv\build\x86\vc10\lib]
At last some threads I have already read:
Compressing IplImage to JPEG using libjpeg in OpenCV - 1
Compressing IplImage to JPEG using libjpeg in OpenCV - 2
Need help in reading JPEG file using libjpeg
how can i use jpeg_mem_src, jpeg_mem_dest in libjpeg-turbo?
If there is something missing you want to know I will do my best to add this information!
EDIT - Some error messages:
1>jpeg_coder.obj : error LNK2001: unresolved external symbol ""unsigned char * image_buffer" (?image_buffer##3PAEA)".
1>jpeg_coder.obj : error LNK2001: unresolved external symbol ""int image_height" (?image_height##3HA)".
1>jpeg_coder.obj : error LNK2001: unresolved external symbol """int image_width" (?image_width##3HA)".
First symbol should be typedefed in jpeglib.h as JSAMPLE FAR *JSAMPROW,
second and third are defined in rdjpgcom.c as unsigned int image_height, image_width;
Maybe, with a lot of luck, I figured out what is need to be done to get jpeglib running. In the current state I have to check and double check whether my problem solution is correct or not. At this point thank you very much for your attention for my issues. As soon as I am sure with the solution I will post it.
Problem Solution: I did not setup OpenCV correctly for using jpeglib. The mistake I made was to link the wrong *.lib-file. The proper file for linking is libjpegd.lib. Too bad that jpeglib v6.2 is included in OpenCV 2.4.6 instead of v9. The hint to add HAVE_JPEG to use jpeglib functions inside OpenCV I ignored completely. For now the problem is solved.
Problem Solution: I did not setup OpenCV correctly for using jpeglib. The mistake I made was to link the wrong *.lib-file.
The proper file for linking is libjpegd.lib.
Too bad that jpeglib v6.2 is included in OpenCV 2.4.6 instead of v9. The hint to add HAVE_JPEG to use jpeglib functions inside OpenCV I ignored completely. Thanks to all who tried solving this issue. For now the problem is solved.

CAP_PROP_FRAME_WIDTH undeclared in 'How to build applications with OpenCV inside the Microsoft Visual Studio' sample code

I'm following the instructions in How to build applications with OpenCV inside the Microsoft Visual Studio but I'm getting errors from the sample code:
error C2065: 'CAP_PROP_FRAME_WIDTH' : undeclared identifier
error C2065: 'CAP_PROP_FRAME_HEIGHT' : undeclared identifier
error C2065: 'CAP_PROP_FRAME_COUNT' : undeclared identifier
I think the identifiers that are undeclared should be declared in highgui so why am I not getting them despite the demo code's #include <opencv2/highgui/highgui.hpp>?
Here are the steps I have taken.
I've unpacked the OpenCV (Version 2.4.6) files into C:\OpenCV, run setx -m OPENCV_DIR C:\OpenCV\Build\x64\vc11 from an elevated command prompt and added %OPENCV_DIR%\bin to my path (following instructions in Installation in Windows). Then using the Property pages (View -> Property Pages or Shift-F4) set to 'All Configurations'
I've added $(OPENCV_DIR)\..\..\include to my C/C++ Additional Include Directories
I've added $(OPENCV_DIR)\lib to the linker Additional Library Directories
I've cut-an-paste the directory listing of the lib files in C:\OpenCV\build\x64\vc11\lib into my input Additional Dependencies
I've copied the sample code from the article into a new C++ console app (with ATL). I had to change one line in the template code from int _tmain(int argc, _TCHAR* argv[]) to int _tmain(int argc, char* argv[])
I think the identifiers that are undeclared should be (are) declared in highgui so why am I not getting them despite the demo code's #include <opencv2/highgui/highgui.hpp>?
Other people having similar issues getting this sample code working in the How to build applications with OpenCV inside the Microsoft Visual Studio note seem to fall over with link errors (e.g. here and here) but I am getting past the linker.
========== EDIT ==========
There appear to be more insurmountable difficulties with the sample code. It is documented as a simple example to load and display an image whose path is supplied as the sole argument to main, while the code listing itself is video code requiring four command line arguments (i.e. it first checks and stops if argc != 5). I've submitted a documentation bug. I think the sample code listing should have been be taken from this: https://github.com/Itseez/opencv/blob/master/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp
Try with CV_CAP_ or cv::CAP_... It looks like there were some changes aiming to improve consistency of constants in OpenCV...
I am using the opencv 2.4.6 and this has helped me do the trick
change CAP_PROP_FRAME_WIDTH into CV_CAP_PROP_FRAME_WIDTH
change CAP_PROP_FRAME_HEIGHT into CV_CAP_PROP_FRAME_HEIGHT
change CAP_PROP_FRAME_COUNT into CV_CAP_PROP_FRAME_COUNT
and similarly if there are any other cap prop keywords into cv cap prop keywords
try this.

Need help installing the GNU Scientific Library for Lisp(GSLL)

I use Emacs\Slime\SBCL\QuickLisp\Cygwin(new to Cywgin I know nothing really about it) I, per this GNU link http://common-lisp.net/project/gsll/, tried to follow these instructions under the download and install section:
"You will need to make sure that the libraries and header files associated with GNU Scientific Library (GSL) and libffi are installed; your distribution may name these libgsl0-dev and libffi-dev. Once they are installed and you have loaded the quicklisp file:
run (ql:quickload "gsll")"
but its not working . I get this error message in emacs when running (ql:quickload "gsll")
Unable to load any of the alternatives:
("libffi-6.dll" "libffi-5.dll" "libffi.dll")
[Condition of type CFFI:LOAD-FOREIGN-LIBRARY-ERROR]
I have quicklisp installed correctly i use it all the time so I know its not that ....I don't really understand this part of above excerpt from website(above)
"your distribution may name these libgsl0-dev and libffi-dev." Once they are installed and you have loaded the quicklisp file"
well I do kind of and quicklisp can't seem to find them with "(ql:system-apropos "libffi")" or "(ql:system-apropos "libffi")" also the website(above link) names these dependencies, I think here in this exerpt:
"Requirements
GSLL should work in any Common Lisp implementation and platform combination for which the following are supported:
GSL
CFFI and cffi-grovel, version 0.11.0 or newer; callbacks and foreign-funcall must be supported.
trivial-garbage
Antik
ASDF
Osicat
lisp-unit, (Optional) necessary to run the tests
FSBV, (Optional) necessary for functions using complex scalars or simulated annealing
iterate and asdf-system-connnections, (Optional) provides a convenient way to iterate over elements or indices of vectors or matrices."
of the above I have CFFI CFFI-Grovel,trivial garbage, asdf,iterate ,Antik(all from quicklisp) but still can't figure it out please help me with step by step instructions for Windows 8 64-bit with perfectly functioning Emacs\Slime\SBCL\QuickLisp\Cygwin installed and available...I would appreciate any and all advice..Thank You
Note: now of these - Excerpt from website http://comments.gmane.org/gmane.lisp.gsll/257"
To load "gsll":
Load 3 ASDF systems:
alexandria cl-ppcre split-sequence
Install 20 Quicklisp releases:
antik asdf-system-connections babel bordeaux-threads
cffi chunga cl+ssl cl-base64 drakma flexi-streams fsbv
gsll iterate osicat puri static-vectors
trivial-features trivial-garbage trivial-gray-streams
usocket"
I have all but Osicat. GSLL, and fsbv. When I try to load GSLL with
(ql:quickload "gsll")
I get:
Error while trying to load definition for system gsll from pathname
D:/Users/W/AppData/Roaming/quicklisp/dists/quicklisp/software/gsll-20130312-git/gsll.asd:
Unable to load any of the alternatives:
("libffi-6.dll" "libffi-5.dll" "libffi.dll")
[Condition of type ASDF:LOAD-SYSTEM-DEFINITION ERROR]
When I try to load Osicat with
(ql:quickload "osicat")
I get:
Error while invoking <COMPILE-OP (:VERBOSE NIL) {26FB8F59}> on
<CL-SOURCE-FILE "osicat" "src" "osicat">
[Condition of type ASDF:COMPILE-ERROR]
and quicklisp doesn't have FSBV.....Any Help would be appreciated.
;;;;;;;;;;;;;;;;EDIT;;;;;;;;;;;;;;;;;;;
#Nelson
Made new progress on this one ...I got past the:
"Error while trying to load definition for system gsll from pathname
D:/Users/W/AppData/Roaming/quicklisp/dists/quicklisp/software/gsll-20130312-git/gsll.asd:
Unable to load any of the alternatives:
("libffi-6.dll" "libffi-5.dll" "libffi.dll")
[Condition of type ASDF:LOAD-SYSTEM-DEFINITION ERROR]"
Error Message when I ran (ql:quickload "gsll") in Emacs. I did it by downloading the LIBFFI tarball from here:
http://sourceware.org/libffi/ ..the link at the top of page.
then i followed this tutorial http://phosphor-escence.blogspot.com/2011/08/build-libffi-and-libyaml-on-mingw-for.html
to build LIBFFI with a correctly installed MinGW(installed at C:\MinGW)
I learned to install MinGw correctly here: http://www.mingw.org/wiki/Getting_Started
after building LIBFFI I added its path - D:\libffi-3.0.13 - to my "system" Environment Variables "path" variable:
D: is my root drive.
I searched the D:\libffi-3.0.13 folder in Windows Explorer by putting *.dll in search bar, found libffi-6.dll
and put it in D:\Program Files (x86)\Steel Bank Common Lisp\1.1.4 so SBCL could access it , the libffi-6.dll
was named in the previous error message:
Error while trying to load definition for system gsll from pathname
D:/Users/W/AppData/Roaming/quicklisp/dists/quicklisp/software/gsll-20130312-git/gsll.asd:
Unable to load any of the alternatives:
("libffi-6.dll" "libffi-5.dll" "libffi.dll")
[Condition of type ASDF:LOAD-SYSTEM-DEFINITION ERROR]
Jobs not done though...now I'm getting this Error Message, Which I will start on Tomorrow:
"Error while trying to load definition for system gsll from
pathname
D:/Users/W/AppData/Roaming/quicklisp/dists/quicklisp/software/gsll-20130312-git/gsll.asd:
External process exited with code 1.
Command was: "C:/MinGW/bin/gcc.exe" "-m32" "-I/Program Files (x86)/Steel Bank Common Lisp/1.1.4/site/cffi/" "-o" "D:\Program Files (x86)\Steel Bank Common Lisp\1.1.4\site\cffi\libffi\libffi-win32.exe" "D:\Program Files (x86)\Steel Bank Common Lisp\1.1.4\site\cffi\libffi\libffi-win32.c"
Output was:
[Condition of type ASDF:LOAD-SYSTEM-DEFINITION-ERROR]"
Any help in the meantime would be appreciated:
;;;;;;;;;;SOLVED;;;;;;;;;;
A Tutorial link for it is coming soon and will posted right
under this point<-----here.
Here it is Fellow Lispers..I give you GSLL on Windows 7 AND 8: https://wnetai.wordpress.com/how-to-install-gsll_the-gnu-scientific-library-for-lisp-on-windows-7-and-windows-8/
and here is a link of GSLL Error Mesages and their Solutions: https://wnetai.wordpress.com/how-to-install-gsll_the-gnu-scientific-library-for-lisp-on-windows-7-and-windows-8/error-message-you-may-get-when-installing-gsll-and-their-solutions/
I'm working on a Database of Code Snippets for GSLL starting with Linear Algebra which will be on the same Blog as those upper two links so stay tuned here and on my Lisp Blog for those. Its basically a How to use GSLL Tutorial made with Code Snippets, Descriptions of the Snippets and Examples.
Your problem is that the development version of libffi (with header files) is not installed. There might be windows users on the cffi-devel mailing list that could help you with that; I recommend you post your question there. As far as the lisp libraries are concerned, quicklisp should take care of that and they are irrelevant to your problem. (And also, FSBV is obsolete and not needed; thanks for pointing out that the documentation needs to be updated.) (Also, emacs and slime are irrelevant to the problem, tags should be removed.)
It seems like you need to install those libraries into your system, you'll have to find the windows equivalents.
For debian/ubuntu : http://pkgs.org/download/libffi-dev
These aren't installed through quicklisp but through the system package manager, in your case you will have to find a windows compatible version and install it.
Any luck with getting GSLL to work on Windows 7? I've been trying to install the software and
have even used Dependency Walker to track any missing DLLs that might be needed but still have not been able to get it to run. I do have it running fine on Linux but I am looking to have it running under Window 7.

How to compile my c program which uses opencv

I have started learning OpenCV.
I am working on linux.
From their documentation page I was able to compile this
http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc-usage
However after that I got lost in trying to declare a new mat and it's constructors.
SO I decided to go with this book http://www.amazon.com/Learning-OpenCV-Computer-Vision-Library/dp/0596516134
However I am not able to compile the very first program from this book.
The program is here :
#include "highgui.h"
int main(int argc, char** argv)
{
IplImage* img = cvLoadImage (argv[1]);
cvNamedWindow("Example1", CV_WINODW_AUTOSIZE);
cvShowImage("Example1",img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Example1");
}
I saved this in a file named load.c
Then I created a CMakeLists.txt file and put this in it :
project( load )
find_package( OpenCV REQUIRED )
add_executable( load load )
target_link_libraries( load ${OpenCV_LIBS} )
when running "cmake ." from terminal it is succesful. But when I am running "make" it gives me this error :
Scanning dependencies of target load
[100%] Building C object CMakeFiles/load.dir/load.o
/home/ishan/load/load.c: In function ‘main’:
/home/ishan/load/load.c:4:2: error: too few arguments to function ‘cvLoadImage’
/usr/local/include/opencv2/highgui/highgui_c.h:212:18: note: declared here
/home/ishan/load/load.c:5:28: error: ‘CV_WINODW_AUTOSIZE’ undeclared (first use in this function)
/home/ishan/load/load.c:5:28: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [CMakeFiles/load.dir/load.o] Error 1
make[1]: *** [CMakeFiles/load.dir/all] Error 2
make: *** [all] Error 2
I think it is because this example in the book is for OpenCV 1.x while I am currently running 2.4.3, however I believe there must be a way to run this program and the subsequent program that are in the book.
I think the problem lies with linking the header files properly.
I would like to first read from the book and using reference from documentation and then switch to documentation fully. But for now I wish to learn from the book as learning from the book is far easier to me than documentation. Plus I bought this book for approx 3000 INR and got it just today, I don't want to see it go to waste. I want to learn from it.
Please help me out.
CV_WINODW_AUTOSIZE is mispelled. The correct constant is CV_WINDOW_AUTOSIZE
cvLoadImage (argv[1]); should be cvLoadImage (argv[1], 1); (for loading a color image) because the C standard does not support default arguments.
By the way, if you're using OpenCV 2.0+, I recommend learning the C++ API. It's a lot less convoluted than the C API and performance is comparable.

Resources