Jump to content


p4 C++ api problems with Visual Studio 2015

c++ api vs visual studio linking windows visual studio 2015 cpp

  • Please log in to reply
5 replies to this topic

#1 Peregrin

Peregrin

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 12 September 2017 - 12:54 PM

I've spent so much time trying to figure out how to start simple app with p4api with Visual Studio on Windows.
I'm using Windows 10, Visual Studio 2015.
I read the latest docs here https://www.perforce...p4api/p4api.pdf and tried to follow as strictly as possible. But nothing worked.
The most frustrating think for me was the discrepancy in documentation. For example, the last version of p4api is 2017.1 for vs2015 (which I tried to use) has only 3 libraries in it: libclient.lib, librpc.lib and libsupp.lib, although documentation requires you to again one more - libp4sslstub.lib. My guess is that it is already included in one of those 3.
Trying different combinations of compiler flags (like Runtime Librariy) I get different outputs:

with /MT flag
1>librpc.lib(netsslcredentials.obj) : error LNK2019: unresolved external symbol BIO_new referenced in function "public: void __cdecl NetSslCredentials::GetExpiration(class StrBuf &)" (?GetExpiration@NetSslCredentials@@QEAAXAEAVStrBuf@@@Z)
1>librpc.lib(netsslcredentials.obj) : error LNK2019: unresolved external symbol BIO_ctrl referenced in function "public: void __cdecl NetSslCredentials::GetExpiration(class StrBuf &)" (?GetExpiration@NetSslCredentials@@QEAAXAEAVStrBuf@@@Z)
1>librpc.lib(netsslcredentials.obj) : error LNK2019: unresolved external symbol BIO_free_all referenced in function "public: void __cdecl NetSslCredentials::GetExpiration(class StrBuf &)" (?GetExpiration@NetSslCredentials@@QEAAXAEAVStrBuf@@@Z)
...

with /MTd flag

1>librpc.lib(netsslendpoint.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
1>librpc.lib(netsslendpoint.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in main.obj
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libcpmtd.lib(StlCompareStringA.obj) : error LNK2001: unresolved external symbol _free_dbg
...

I compile x64 debug version

#2 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 976 posts

Posted 12 September 2017 - 08:37 PM

I haven't tried to link a P4API app from the prebuilt libraries since before the SSL stuff was added but I suspect the missing SSL stub library is the culprit -- probably a bug in the API build.  I don't see P4SSLLIB in the build rules for the API distribution, although there is a Jamfile for it so it shouldn't be hard to add:

https://swarm.worksh...api/Jamfile
https://swarm.worksh...sslstub/Jamfile

If you're feeling adventurous you could try to learn Jam and fix api/Jamfile so you can build the libraries from source.  

Alternatively, have you tried tracking down the "real" SSL library mentioned in the doc and linking that one in there?

#3 Peregrin

Peregrin

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 15 September 2017 - 07:47 AM

No, I didn't try it. I just wanted the thing to compile.
I wonder if it's going to be fixed or at least docs are going to be updated.
At this moment I have to use 2015.2 version of api since it's the only one that worked for me.
Just for the record: the latest at the moment is 2017.1

#4 xmclark

xmclark

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 29 October 2017 - 05:08 AM

It looks like the last good build of API that produces the ssl stub is for ntx86 is r16.2. It's too bad that they haven't fixed this :(. I'm not sure how to to report a bug. I will be using 16.2 until this is fixed because it's not worth my time trying to build API just to get the stub.

#5 TwistyMazeOfPassages

TwistyMazeOfPassages

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 18 September 2018 - 07:23 PM

I'm another in the same boat but with VS2017. I got the same linker errors as the OP. I installed the most recent OpenSSL. and still get linker errors.  Why doesn't your sample just compile and run?  Why must I build external APIs just to get it to run?  I appear to still be missing a lib but no idea which one. *ssleay*.lib is not part of any of the libs that come with VS2017.  You might also add in your docs that Ws2_32.lib is also required.  I'm going to try and punt like as well and try 2016-2.

1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol SSLeay
1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol CRYPTO_num_locks
1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol CRYPTO_set_locking_callback
1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol CRYPTO_set_id_callback
1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol CRYPTO_set_dynlock_create_callback
1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol CRYPTO_set_dynlock_lock_callback
1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol CRYPTO_set_dynlock_destroy_callback
1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol SSL_load_error_strings
1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol SSLv23_method
1>librpc.lib(netssltransport.obj) : error LNK2001: unresolved external symbol SSL_library_init



#6 LSFRNCSC

LSFRNCSC

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 11 April 2019 - 12:50 AM

Hi am having similar issues, new to the API stuff and following the guide is not working for me. Did anyone found a solution for your problems?





Also tagged with one or more of these keywords: c++, api, vs, visual studio, linking, windows, visual studio 2015, cpp

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users