Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC linker error json_c_strerror #347

Closed
alexukr opened this issue Aug 9, 2017 · 15 comments
Closed

MSVC linker error json_c_strerror #347

alexukr opened this issue Aug 9, 2017 · 15 comments

Comments

@alexukr
Copy link

alexukr commented Aug 9, 2017

This is probably related to #336

I link my cross-platform program (Linux/Mac/Windows) with json-c.

Today I updated and rebuilt json-c from master. Mac and Linux builds are ok, on Windows I get the following error:

error LNK2019: unresolved external symbol __json_c_strerror referenced in function __json_object_to_fd

The json-c library itself has been built successfully, but my program that links with it fails to be built now.

Using MSVC 14 (2015), 32-bit build, both Debug and Release fail.

I rolled back to this commit: c0b7d76, rebuilt json-c and after that I was able to link my program with it successfully.

@wenhuancai
Copy link

i test the file of test_util_file is error!
test_util_file.obj : error LNK2001: int _json_c_strerror_enable" (?_json_c_strerror_enable@@3Ha)
link c:\program files (x86)\microsoft visual studio 9.0\vc\include\string.h(126) : warning C4985: “_json_c_strerror”: .
What should I do?

@Haffon
Copy link
Contributor

Haffon commented Aug 29, 2017

you need add "strerror_override.c" file to vs project.

@alexukr alexukr closed this as completed Aug 29, 2017
@alexukr alexukr reopened this Aug 29, 2017
@alexukr
Copy link
Author

alexukr commented Aug 29, 2017

you need add "strerror_override.c" file to vs project.

Just an empty file to https://github.com/json-c/json-c?

@wenhuancai
Copy link

Thank you for alexukr! I disregarded it(extern int _json_c_strerror_enable = 0;) in( test_util_file.cpp).i don't know ,What's the role of ' _json_c_strerror_enable' .and i have a waring. for _json_c_strerror.c:\program files (x86)\microsoft visual studio 9.0\vc\include\string.h(126) : warning C4985: “_json_c_strerror”. I've added it(#define _CRT_SECURE_NO_WARNINGS) and strerror_override.c

@hawicz
Copy link
Member

hawicz commented Aug 31, 2017

The files json-c.vcproj, json-c.vcxproj and json-c.vcxproj.filters are out of date with respect to their lists of source files and headers. While presumably I could just hand edit those, it would probably be better for someone with a Windows build environment to add the files to the VS project, as @Haffon suggested.
Can one of you do so, and submit a pull request?

@alexukr
Copy link
Author

alexukr commented Aug 31, 2017

I actually don't use json-c.vcproj, json-c.vcxproj and json-c.vcxproj.filters. For my project I have my own cmake file to produce my Visual Studio project files with the settings I need. So the problem was in my cmake file - it didn't add new files (strerror_override.h and strerror_override.c) to the project. After I added them my problem was solved. So the ticket can be closed.

@hawicz
Copy link
Member

hawicz commented Sep 2, 2017

hmm... we have strerror_override.c in CMakeLists.txt, but not strerror_override.h. Did you just add it to the set(JSON_C_HEADERS ...) section ?

@alexukr
Copy link
Author

alexukr commented Sep 2, 2017

I have my own CMakeLists.txt (probably, because there was no CMakeLists.txt in your repo when I started using it). But, regarding your question on JSON_C_HEADERS, you can say so, effectively what I did is I added strerror_override.c to JSON_C_SOURCES and it started to work for me. But just for completeness I added strerror_override.h to my JSON_C_HEADERS as well.
Not sure if it makes difference, but in my CMakeLists.txt I don't have './' in my paths, I just use filenames.

@Haffon
Copy link
Contributor

Haffon commented Sep 4, 2017

I forked this repository and committed so they can be compiled by vs2010. you can download special files you need from it, but don't merge them, as I changed the API. Don't add .vcxproj or .vcxproj.filters to json-c source, as they can be generated by CMake, but I don't know cmake is owner recommend toolchain. Any way, cmake works by change CMakeLists.txt a lit.

@wenhuancai
Copy link

Thank you for @alexukr ,
@Haffon
@hawicz
I'd like to know if the compilation of my project is correct in vs 2008.

//****I modify the file of json_inttypes.h
#ifndef json_inttypes_h
#define json_inttypes_h

#include "json_config.h"

#if defined(_MSC_VER) && _MSC_VER <= 1700
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int8 uint8_t;
/* Anything less than Visual Studio C++ 10 is missing stdint.h and inttypes.h */
typedef __int32 int32_t;
#define INT32_MIN ((int32_t)_I32_MIN)
#define INT32_MAX ((int32_t)_I32_MAX)
typedef __int64 int64_t;
#define INT64_MIN ((int64_t)_I64_MIN)
#define INT64_MAX ((int64_t)_I64_MAX)

#define PRId64 "I64d"
#define SCNd64 "I64d"

#if defined(WIN32) && !defined(__cplusplus)
#define inline __inline
#endif

#else

#ifdef JSON_C_HAVE_INTTYPES_H
#include <inttypes.h>
#endif
/* inttypes.h includes stdint.h */

#endif

#endif

  1. i change a few files (*.c to *.cpp)

3.can you tell me what the function is correct? Or tell me how to make/link the project in win32.

@hawicz
Copy link
Member

hawicz commented Sep 6, 2017

If VS2008 is missing so many things, why keep using it? The changes to make it work in VS2010 look fairly minimal, so I'm inclined to say that VS2008 is simply not supported.
@Haffon, as I said on PR#355, if you re-spin the a pull-request to make things build on VS2010 without the other API-breaking changes mixed in, I'll merge it.

Anyway, that's separate from the immediate issue described here. @Haffon, you said "cmake works by change CMakeLists.txt a lit." What needs to be changed? If that can be fixed, then we'll just drop the checked-in vxproj files.

@Haffon
Copy link
Contributor

Haffon commented Sep 7, 2017

@hawicz I see. I will change back the API and spin another pull request. In fact the strerror_override.c should conditional include to project by STRERROR_OVERRIDE_IMPL macro, it seem's not defined in default, so the strerror_override.c file should include to project by default. The conclusion is: we should keep update the cmake script to reflect this logical, but I'm new guy to cmake, give me some time if no other updating it.

@wenhuancai
Copy link

Thanks for everyone! I can learn lots of knowledge.

@hawicz
Copy link
Member

hawicz commented Sep 7, 2017

No, strerror_override.c should always be included, it is NOT conditional. The STRERROR_OVERRIDE_IMPL define is so the code in strerror_override.c can be compiled without the "strerror" symbol being renamed, otherwise _json_c_strerror() would end up calling itself in an infinite loop.

@hawicz
Copy link
Member

hawicz commented Sep 7, 2017

With the changes from PR#359, and the removal of the old project files in commit e1561ed, I think this issue can be closed.

@hawicz hawicz closed this as completed Sep 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants