Openssl unresolved external BN_is_zero - c

During the development of a small project using statically linked OpenSSL 1.0.2e I encountered a strange error in VS13:
Error LNK2001: unresolved external symbol _BN_is_zero
Quite often, this happens when you forget to properly liked .lib file in the project properties, but all of the properties were double-checked - they are correct.
Configuration - Release, MT, libs are MT, bh.h included.
And even if one of the libraries is not linked properly, I should have multiple compiler errors complaining about unresolved external symbols of all the elements used in the project, but in my case unresolved external symbol is the only BN_is_zero.
After quick googling there wasn't found any issues, related to openssl bugs and I guess that the problem resides at my project.
Any tips will be appreciated.
UPD
Here is some screens:

I actually forked the csrp github project and compiled it against the particular openssl libraries you are pointing at. I had to slightly modify test_srp.c and src.c to add some code that isn't available on VS2013. A fork of csrp with the changes applied and the visual studio project for VS2013 to compile it can be found here:
https://github.com/sigmoidal/csrp
Note that you need to change the paths of the openssl path on BOTH the debug and release versions to reflect your VS Configuration Properties:
C/C++ > General > Additional Include Directories
D:\dev\openssl\openssl-1.0.2e-vs2013\include
(you should not point it to $openssl_path/include/openssl, it will not work)
and also:
Linker > Input > Additional Dependencies:
For release configuration:
D:\dev\openssl\openssl-1.0.2e-vs2013\lib\libeay32MT.lib
D:\dev\openssl\openssl-1.0.2e-vs2013\lib\ssleay32MT.lib
For debug configuration:
D:\dev\openssl\openssl-1.0.2e-vs2013\lib\libeay32MTd.lib
D:\dev\openssl\openssl-1.0.2e-vs2013\lib\ssleay32MTd.lib
(notice the "d" suffix on debug libs)
Compiled ok for me.

I'm guessing here, but according to the OpenSSL source BN_is_zero is defined as a macro:
http://osxr.org/openssl/source/crypto/bn/bn.h#0407
So perhaps the module that is compiled into srp.obj is making a call to BN_is_zero but is not including bn/bn.h and in the absence of a prototype the compiler is generating a default one.
If this is the case, including the bn.h definitions should avoid the linker error.

It was tricky, but I've finally solved it based on the Drew MacInnis tips.
The matter is that openssl 1.0.2e broke the BN_is_zero functionality by simply removing the macros-containing header from sources. So, the solution is:
Download the bn.h include file from 1.0.1h (or here)
Place bn.h to %OPENSSL_HOME%/crypto/bn directory
Change #include <openssl/bn.h> for #include <../crypto/bn/bn.h>

Related

CCS unresolved symbols in linker or compiler causing errors

I am newbee c programmer so be patient. I have a MSP430 C project in Code Composer Studio 7.3 using windows 7. My project (USB) was working fine and then I tried to add more code to incorporate a SPI interface and everything went sideways. I restored my original code but now have problems that weren't there before. Seems to compile but has several unresolved symbols errors in the linker (I think). I have searched/researched many answers to these types of problems on the forum and tried many things (over the past two days!!) and cannot resolve my problem. Possibly I made things worse by copying library/functions directly into my project directory but still didn't seem to change anything. The errors are related to standard MSP430 functions, not my code. My project tree looks like:
project tree
Errors from Console are:
console errors
From everything I have read it indicates that either I have a compiler library path problem or a linker file path problem. Tried a lot of combinations to no avail. Following are the compiler and linker path info:
linker 1
linker 2
If I look in my repository of library stuff downloaded from TI you can see that the dma.h and dma.c files which reference the error message lines in the files are there and I don't understand why the linker can't do its thing.
dma file tree
In the linker under library files I noticed the original libmath.a file didn't point to anything so I found one and added it (not help). Also the libc.a points to a section of 3 directories (different versions of a tool) which each have a different version of libc.a and I think I tried all of them. See below for directories
directories
Any help would be greatly appreciated
A CLUE POSSIBLY: CLUE? In my quest to solve my issues, I created a new CCs project and pasted my main.c file in and then went through a series of compiles solving the errors as the showed up. I was down to one error : can't open source file hal.h. I believe this is a file that was included with the usb example code I started with. After copying it into my project I am back to square on with all the errors listed above. To get here I only needed to point the compiler to driverlib to solve previous errors. The hal.h file seems to only include driverlib.h which is also referenced in my main function so why all the errors??
FIXED BUT WHY!!!
To solve this issue I imported the drivlib directory from the TI repo on my D drive into my project. Now everything compiles. Can anyone tell me why I had to do that given that I had path directives to look on my D drive?? Can it be related to search path length being too long?

unresolved external symbol (still occurring)

When building my application in Debug mode: The build works. The application works.
When building my application in Release mode, I get the following error message
error LNK2019: unresolved external symbol __imp__GetClassNameA#12 referenced in function _eachWindow#8
All implementation files of my application have a .c extension; that however doesn't mean I would know which compiler is used by visual studio.
From the documentation of GetClassNameA I can see that a library User32.lib is required. I have found a library with that name in
C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib>
I have added that directory to the property pages:
Configuration Properties > Linker > General > Additional Library
Directories
but that did not help. I am still receiving that error message.
Thanks for help. I know this question has been asked before, but the previous answers did not help me.
Please help in baby steps, I am still overwhelmed by Windows programming.
Does _eachWindow call GetClassName? Then you need to link user32.lib. Check the additional dependencies in the project's linker settings, not the additional library directories.
– dxiv
dxiv's comment … makes the application work. – chris j

Compiling specific apache module in VS2010

Over the last few days I've been tinkering with mod_pLua on Windows (https://sourceforge.net/projects/modplua/ or https://github.com/Humbedooh/mod_pLua).
The pre-built Windows binary works a treat, except it doesn't seem to have been compiled with mod_dbd support for database connectivity. The documentation suggests that to enable this feature you must compile with a certain tag, so I've been trying to compile the module in VS2010 - hoping that I'll be able to get mod_dbd support working at some point - but I've run in to a snag. It just will not compile.
What I've done so far:
Included apache/include and apache/lib, which got rid of a lot of
errors
Included lauxlib.h, lua.h, luaconf.h and lualib.h from Lua 5.2, which got rid of a lot of errors
Compiled a .lib file from Lua 5.2 sources and included it, which fixed a few errors
The errors I'm getting at the moment are:
error LNK2019: unresolved external symbol _luaL_openlib referenced in function _lua_dbopen C:\Users\Michael\Desktop\Projects\C\mod_plua\mod_plua.obj
And a plethora like this:
IntelliSense: a value of type "const char ()(cmd_parms *cmd, void *cfg, const char *arg)" cannot be used to initialize an entity of type "cmd_func" c:\users\michael\desktop\projects\c\mod_plua\mod_plua.h 394 5
As I'm not a C/C++ native, I only have a vague idea of what's wrong, and have likely done something wrong in my attempts to fix the issue. If someone could guide me in the right direction (or better yet, write a little instructional on how to compile the module from start to finish) I would be so happy.
I've uploaded my VS2010 project files and source here: https://dl.dropboxusercontent.com/u/51243175/mod_plua_vs2010.7z
Self-answer:
The primary reason for the failure to compile was the Lua .lib file. The Microsoft compiler does strange things when dealing with C code, so I got an appropriately compiled version of the .lib from the LuaBinaries SourceForge repository (http://sourceforge.net/projects/luabinaries/) - specifically, 5.2.3/Windows Libraries/Dynamic/lua-5.2.3_Win32_dll10_lib.zip (which is compiled for VS2010).
This didn't enable mod_dbd support, which requires headers and sources from the Apache APR project, but it did allow successful compilation.
You should not be using mod_pLua really, I haven't worked on that for nearly 3 years ;) You should use mod_lua instead, which comes bundled with httpd and works pretty much the same way (although it does not support the php-like scripting that mod_pLua does)
For DBD specific setups (especially how to use it on Windows), see http://modlua.org/api/database

An odd linkage diffrence between Debug and Release resulting an unresolved _except_handler3, or Why, oh, why I don't know about libcmtd?

A windows application I've been working on, is due to delivred without the use of CRT.
There's a few good articles descirbing the guidlines and benefits of doing so (none of which I could find upon writing this question - sorry) . Other then not using CRT symbols explicitly, it's all about linker and compailer configuration. My Release and Debug configurations are nearly identical now , and both specify /NODEFAULTLIB:"LIBCMT" only diffrence is the Run time flag /MT (in Release) vs. /MTd (in Debug) - that is required as I'm using __try/__except syntax for SEH, and so the only needed function is _except_handler3(). However, the Debug version is beeing built successfully, and the Release version fail with Unresolved Symbol _except_handler3 linkage error. When forcing Release version to compile with /MTd - this issue is solved.
How is that possible? which .lib contains the _except_handler3 export? and how can I solve this?
For an application without CRT see: http://blog.kalmbach-software.de/2008/02/02/smallest-application-size-for-win32-console-application/
But if you want to use __try / __except you need to use the CRT; or you need to write your own "_except_handler3".
See also: _except_handler3
Also you have the CRT source, and you can take a look into the source, to see what it is doing!
See: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src

Waveform API linking error

I'm getting some kind of linking error with a program utilizing MS-s waveform API. The code I'm using can be found here: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4422&lngWId=3
It's the first bit of code on the page under the heading "Opening the Sound Device". I'm not getting any errors with the code, however my linker complains quite persistently. The output being the following:
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\crt2.o:crt1.c|| undefined reference to `SetUnhandledExceptionFilter#4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\crt2.o:crt1.c|| undefined reference to `ExitProcess#4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\crtbegin.o:cygming-crtbegin.c|| undefined reference to `GetModuleHandleA#4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\crtbegin.o:cygming-crtbegin.c|| undefined reference to `GetProcAddress#8'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(pseudo-reloc.o):pseudo-reloc.c|| undefined reference to `VirtualQuery#12'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(pseudo-reloc.o):pseudo-reloc.c|| undefined reference to `VirtualProtect#16'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(pseudo-reloc.o):pseudo-reloc.c|| undefined reference to `VirtualProtect#16'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\libgcc.a(cygming-shared-data.o)||In function `cmshared_get_ptr_from_atom':|
c:\crossdev\b4.4.1-tdm-1\build-sjlj\mingw32\libgcc\..\..\..\..\gcc-4.4.1\libgcc\..\gcc\config\i386\cygming-shared-data.c|91|undefined reference to `GetAtomNameA#12'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\libgcc.a(cygming-shared-data.o)||In function `_cmshared_create_or_grab':|
c:\crossdev\b4.4.1-tdm-1\build-sjlj\mingw32\libgcc\..\..\..\..\gcc-4.4.1\libgcc\..\gcc\config\i386\cygming-shared-data.c|140|undefined reference to `FindAtomA#4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\libgcc.a(cygming-shared-data.o)||In function `cmshared_add_ptr_as_atom':|
c:\crossdev\b4.4.1-tdm-1\build-sjlj\mingw32\libgcc\..\..\..\..\gcc-4.4.1\libgcc\..\gcc\config\i386\cygming-shared-data.c|118|undefined reference to `AddAtomA#4'|
||=== Build finished: 10 errors, 0 warnings ===|
I can paste the build log here as well if need be. Could anybody let me know what I need to do to fix this? Or even better, how to troubleshoot it myself so I can fix future problems like this myself?
[EDIT]: Okay so I managed to solve this. While playing around in Project->Build Options->Linker Settings->Link Libraries I noticed that if I add something like kernel32.lib I get an error from ld saying "cannot find -lkernel32.lib". So I searched around till I found the libraries I required and I added absolute paths to them, and now my project compiles flawlessly! :D However this was kind of strange since I did add my library search path and it didn't seem to help. So I went over it again to see why it didn't seem to work and it seems like one has to add a trailing backslash to the path name, like if the libraries are located in "C:\SDK\Lib\" one has to add the trailing slash for Code::BLocks to search it correctly. Once that was fixed I changed the option in Linker Settings->Link Libraries to kernel32 as was recommended and now it works without a hitch.
Thanks to everybody who helped me out with this!!! ^_^
I got the same errors when I place a library into system32 and try to link to it with LIBS += L$$quote(C:/Windows/System32).
When I placed it into a normal directory and set the relative path to it, everything works alright.
Looks like you are not linking with Kernel32.lib Check your project properties.
I'd the same problem and after some time I figured out how to do it, the problem relies on the linker, it's trying to link some windows functions into the exe file, and the compiler cannot find those, this is how I solved this:
Install the Windows 7 SDK, you can download it from here: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3138
Add the library path to the search libraries on CodeBlocks
Project / Build Options (select The project if you want to link it to all the configurations you have) / Search Directories / Linker / Add and place the SDK Library path, which should be at: C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib
Add the references to the windows libraries on the linker settings:
Project / Build Options / Linker Settings / Add (at Link Libraries) and add kernel32, user32 and gdi32 (this last one should be added if you're using windows gui).
That's it... now rebuild your project and it should work flawlessly.
Note: You need to add this settings to the exe project, if you're creating libraries the error will be shown when try to link the exe file.

Resources