Closed zdenop closed 3 years ago
That is very strange. The global LeptMsgSeverity is defined in utils1.c, and it is declared and used in ERROR_INT in environ.h.
If you are linking the library, it includes these two files. Does it matter if the .h file occurs before the library on your compile/link command at the top?
Also, did this only happen for pixafileinfo?
Also, does it give the error when you do static linking instead of shared?
When I build leptonica (AFAIK as static) this way:
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DSW_BUILD=OFF -DBUILD_PROG=ON
it works (and it built other leptonica programs).
Also I found out that when I add LEPT_DLL l_int32 LeptMsgSeverity;
before main function (in pixafileinfo.c) compilation/linking works with also with shared library .
Actually problem for me is not pixafileinfo.c
build. I tried to build and test one utility on windows that uses leptonica and its build failed with the same error, so I come back to test build of leptonica program by hand to find reason....
OK. I solved it: adding /D LIBLEPT_IMPORTS /TP
made a magic:
cl /If:\win64\include\leptonica /D LIBLEPT_IMPORTS /TP pixafileinfo.c /link /LIBPATH:f:/win64/lib leptonica-1.81.0.lib
I found it when I look at details why cmake was able to build progs with shared libs ( -DSW_BUILD=OFF -DBUILD_PROG=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_VERBOSE_MAKEFILE=ON
)
Thank you for solving the problem -- I knew it was above my pay grade.
Do you think something should be added to the build setup or instructions, or are you using a method of building that is non-standard? (Hint: nobody has reported this problem before you).
I do not know. If somebody builds progs with cmake, there is no problem. Problem is "only" on windows with VS (or clang-cl), so information in this issue should be sufficient.
Adding comment for other developers using only Visual Studio (VS) as building tool (no CMake or command line).
I had same issue building from new VS and including code from skewtest.c and using leptonica-1.84.0d.lib in a test program I made.
Adding LIBLEPT_IMPORTS to preprocessor directive in my program was helpful, it resolve the LeptMsgSeverity not found.
But the other issues afterward were the missing functions for all the functions from Leptonica. The use of /TP is good advice too, as above example is using command line for "cl", it can be confusing as VS does not permit to add file after /TP option enable in GUI. So for those, that use GUI, activate the /TP option on the Leptonica project since it is the leptonica-1.84.0d.lib that need to be C++ compatible when imported from a C++ project. This resolve my missing function in linker step as now the function were C++ named.
Hope this help other.
I am not sure if I do something wrong but when I tried to compile e.g. pixafileinfo with:
cl /Fe pixafileinfo.c /If:\win64\include\leptonica /link /LIBPATH:f:/win64/lib leptonica-1.81.0.lib /machine:x64
I got error:
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29914 for x64 Copyright (C) Microsoft Corporation. All rights reserved.
If I replace
return ERROR_INT(...)
withCompilation is successful and program (pixafileinfo.exe) works.
I use the latest leptonica build with cmake and command:
Any idea what could be wrong?