protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.82k stars 15.52k forks source link

error while building an application using protobuf-v3.1.0 on VS2015 #5420

Closed sblola closed 2 years ago

sblola commented 5 years ago

Hi,

I'm using visual studio 2015 c++ to build my project in 64bit. For this, i download and build protobuf - v3.1.0 in 64bit folowing this issue : https://docs.microsoft.com/en-us/cognitive-toolkit/archive/setup-buildprotobuf-vs15. I succed geting the library (libprotobuf.lib) and its dependencies (.dll, .ilk and .pdb). My problem is when compiling my project using this library, i got this error :

1>libprotobuf.lib(zero_copy_stream_impl.obj) : error LNK2019: unresolved external symbol imp_close referenced in function "public: bool cdecl google::protobuf::io::FileInputStream::CopyingFileInputStream::Close(void)" (?Close@CopyingFileInputStream@FileInputStream@io@protobuf@google@@QEAA_NXZ) 1>libprotobuf.lib(zero_copy_stream_impl.obj) : error LNK2019: unresolved external symbol imp_read referenced in function "public: virtual int cdecl google::protobuf::io::FileInputStream::CopyingFileInputStream::Read(void ,int)" (?Read@CopyingFileInputStream@FileInputStream@io@protobuf@google@@UEAAHPEAXH@Z) 1>libprotobuf.lib(zero_copy_stream_impl.obj) : error LNK2019: unresolved external symbol __imp_write referenced in function "public: virtual bool __cdecl google::protobuf::io::FileOutputStream::CopyingFileOutputStream::Write(void const ,int)" (?Write@CopyingFileOutputStream@FileOutputStream@io@protobuf@google@@UEAA_NPEBXH@Z)

I sow and read a lot of issues and tutos but didn't find a solution.

Any help please.

Thank you in advance

acozzette commented 5 years ago

Could you try building with a more recent version (e.g. 3.6.1) and see if that works? I think you might have come across a bug that exists in 3.1 but has been fixed since then.

sblola commented 5 years ago

I had the same problem with version3.0.0 while building it in windows x64. For raison of compatibility with another project, I realy need a version 3.1 64 bits library. If the bug has been fixed for latest versions, so what was the problem?

acozzette commented 5 years ago

I'm not sure what exactly the problem is, but there have been Windows-specific changes related to system calls like close, read, and write (e.g. see here), so that makes me suspect the problem may have been fixed since 3.1.

sblola commented 5 years ago

Hi, Thank you acozzette for your response. Now, I'm trying to use the new version 3.6.1, I built the project and got libraries. I need to generate sources and headers from .proto files, i'm trying to execute protoc.exe (https://github.com/protocolbuffers/protobuf/releases) with a bat file that indicates path to .exe, protocolbuffer files and out files (folder atached below). Could you, please, tell me why i could not generate needed sources? bin.zip

Thank you for your help

sblola commented 5 years ago

please, do not take in account my previous question, i resolved the problem and generated the source files :) instead of .bat file, i used windows cmd : togeneratesourcefiles_withoutusing_batfile

Now, when trying to build my project with version 3.6.1, i got this error :

libprotobuf.lib(io_win32.obj) : error LNK2019: unresolved external symbol __imp_close referenced in function "int __cdecl google::protobuf::internal::win32::close(int)" (?close@win32@internal@protobuf@google@@YAHH@Z)

How can i overcome this problem related to "close" function.

Thank you for help

acozzette commented 5 years ago

Hmm, I'm not sure what the problem could be. If you're able to figure it out we would be glad to take a pull request with the fix.

sblola commented 5 years ago

Hi,

I, finally, resolved the link error. I've just added #define PROTOBUF_USE_DLLS in the generated .h files

the issue i've followed : https://github.com/protocolbuffers/protobuf/issues/3994

Thank you for your help and answers.

acozzette commented 5 years ago

@sblola Do you happen to know why the CMake build isn't already defining that macro? The logic here looks like it should set PROTOBUF_USE_DLLS when it builds a shared library on Windows.

sblola commented 5 years ago

Hi

I dont know why it's not added automaticaly while generating the sources and headers.

The unresolved external error has gone when i've added "#define PROTOBUF_USE_DLLS"

Thank you

On Wed, Dec 19, 2018 at 8:31 PM Adam Cozzette notifications@github.com wrote:

@sblola https://github.com/sblola Do you happen to know why the CMake build isn't already defining that macro? The logic here https://github.com/protocolbuffers/protobuf/blob/4dec4f93710f70829a72849daa7f752a10e28c4d/cmake/libprotobuf.cmake#L128 looks like it should set PROTOBUF_USE_DLLS when it builds a shared library on Windows.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/protocolbuffers/protobuf/issues/5420#issuecomment-448716410, or mute the thread https://github.com/notifications/unsubscribe-auth/ArfKEEAxuJrMheYnLZiOyot4gJ_U7fKiks5u6pQtgaJpZM4ZAxUl .

-- *This e-mail message is intended for the internal use of the intended recipient(s) only. The information contained herein is confidential/privileged. Its disclosure or reproduction is strictly prohibited. If you are not the intended recipient, please inform the sender immediately, do not disclose it internally or to third parties and destroy it.

In the course of our business relationship and for business purposes only, Valeo may need to process some of your personal data. For more information, please refer to the Valeo Data Protection Statement and Privacy notice available on Valeo.com https://www.valeo.com/en/ethics-and-compliance/#principes*

sbenzaquen commented 2 years ago

MSVC 2015 is outside of our supported platforms. Please see our support policy at: https://opensource.google/documentation/policies/cplusplus-support