1

I'm trying to add a project to Visual Studio 2013 that will build OpenSSL in the Visual Studio GUI. I'm using the "makefile" project settings as a starting point.

I've already succeeded in building OpenSSL on a Visual Studio command line window, and it works. However, when I try to build OpenSSL through the project using the exact same commands that I use in the command line, I get linking errors (LNK2001).

Looking at the resulting .lib files with dumpbin, I see that when I build OpenSSL through the GUI, an underscore ('_') is appended to all the exports (So a function that's called BIO_read will become _BIO_read).

Microsoft has this to say about LNK2001: https://msdn.microsoft.com/en-us/library/f6xx1b1z.aspx?f=255&MSPPError=-2147217396

Specifically, it says:

When a symbol is unresolved, you can get information about the function by the following guidelines:

On x86 platforms, the calling convention decoration for names compiled in C, or for extern "C" names in C++, is:

__cdecl

Function has an underscore (_) prefix.

I think that cl is called with slightly different parameters which make it emit underscore prefixes, but I'm unable to figure out what exactly is different - the command line is not different and if there are differences in the environment variables I couldn't find a relevant one.

Any ideas what's going on here?

nitzanms
  • 1,786
  • 12
  • 35
  • 1
    When you run Visual Studio, you can actually see in the build log the *actual* flags and arguments it passes to the linker. Are you saying that if you do the same in the command line, you get different output? If so, check for differences in the Environment settings, the path, etc. – Martin Bonner supports Monica Dec 01 '16 at 17:45
  • @MartinBonner , yes, I've already looked at the build flags passed to cl.exe in the build log (I can see the underscores in the .obj files too), and they don't seem to differ. I ran "set" in the beginning of the commands for the project, but the results didn't seem to have something that I know that affects CL. – nitzanms Dec 01 '16 at 18:12
  • The underscore is prepended to the function name, since it is a prefix. Have you included any necessary libraries in you project file? – 1201ProgramAlarm Dec 01 '16 at 18:16
  • You still have to run OpenSSL's `Configure` script to generate critical files, like `opensslconf.h` and `bn.h`. The script also fixes up the ASM templates that are later assembled *if* you configure *without* `no-asm`. Also see [Build Multiarch OpenSSL on OS X](http://stackoverflow.com/a/25531033/608639), which discusses the files in the context of a fat library on OS X and iOS. – jww Dec 02 '16 at 03:08
  • @1201ProgramAlarm I did, or it wouldn't have worked when I was building the library from the command line. – nitzanms Dec 04 '16 at 08:15
  • @jww I did, or it wouldn't have worked when I was building the library from the command line. – nitzanms Dec 04 '16 at 08:16
  • I encountered the cli & gui difference issue too, but my case is `cli compiled with a underscore prefix but gui without`, the symbol is `BIO_new_bio_pair` which is included from `openssl/bio.h` inside where the symbol is decorated with `extern "C"`. VS2019 community `V16.3.7`, cl.exe:`19.23.28106.4`. Things become weird. – pplorins Aug 29 '20 at 17:20

1 Answers1

0

Running the build through a batch file and removing $(NMakePreprocessorDefinitions) from the Preprocessor Definitions field in the project properties allowed me to build OpenSSL successfully without an underscore prefix.

nitzanms
  • 1,786
  • 12
  • 35