I was able to create a test WinApp using JsonCPP (https://github.com/open-source-parsers/jsoncpp) to parse a json file.
However, when I implemented similar in an MFC C++ project with C/C++ -> Precompiled Headers option set to Use Precompiled Header(/Yu) in VS2008, it fails with this error:
c:\users\user1\documents\visual studio 2008\projects\jsonutility\jsonutility\jsonTest.cpp(371) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
If I add '#include "stdafx.h"' to my JsonTest.cpp, I will get this error:
JsonTest.obj : error LNK2019: unresolved external symbol "public: class Json::Value & __thiscall Json::Value::operator[](char const *)" (??AValue#Json##QAEAAV01#PBD#Z) referenced in function "public: void __thiscall JsonTest::readConfig(char const *)" (?readConfig#JsonTest##QAEXPBD#Z)
I have tried for almost 2 days now but no success.
I had added the following in my Additional Include Directories:
C:\Users\User1\Documents\Visual Studio 2008\Projects\JsonUtility\ReadingJson\dist
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include
C:\usr\jsoncpp-master\include
I seems like you didn't include the JSONCPPs *.cpp file into your project (they have to be compiled and linked). If the library gets compiled to a static library, you have to tell the linker what to link.
Related
I had boost compiled & working on my Visual Studio 2022 project. After the PC was upgraded and the OS changed to Windows 11 I attempted to re-build boost and use it with the same project. Now I get linker errors, and it seems like I have tried every suggested fix posted online. Somehow it seems like the lib files are not being found, even though I have confirmed the include and lib directories are included properly, and have tried rebuilding boost with many different configurations.
The boost build produces libboost_*.lib files, for example
libboost_log_setup-vc143-mt-gd-x32-1_78.lib
libboost_log_setup-vc143-mt-x32-1_78.lib
libboost_log-vc143-mt-gd-x32-1_78.lib
libboost_log-vc143-mt-x32-1_78.lib
Here are my boost build options
x86
b2 -j 16 --stagedir=stage/Win32 threading=multi --toolset=msvc-14.3
link=static runtime-link=shared --build-type=complete architecture=x86
address-model=32
x64
b2 -j 16 --stagedir=stage/x64 threading=multi --toolset=msvc-14.3
link=static runtime-link=shared --build-type=complete architecture=x64
--address-model=64
And my Visual Studio properties
C/C++->General->Additional Include Directories
C:\Program Files\Code Libraries\boost\boost_1_78_0
Linker->General->Additional Library Directories
C:\Program Files\Code
Libraries\boost\boost_1_78_0\stage$(Platform)\lib
And here's an example of the errors
1>Logging.obj : error LNK2019: unresolved external symbol "private: static unsigned int __cdecl boost::log::v2s_mt_nt62::attribute_name::get_id_from_string(char const *)" (?get_id_from_string#attribute_name#v2s_mt_nt62#log#boost##CAIPBD#Z) referenced in function "public: __thiscall boost::log::v2s_mt_nt62::attribute_name::attribute_name(char const *)" (??0attribute_name#v2s_mt_nt62#log#boost##QAE#PBD#Z)
1>Logging.obj : error LNK2001: unresolved external symbol "public: static void __cdecl boost::log::v2s_mt_nt62::aux::stream_provider<char>::release_compound(struct boost::log::v2s_mt_nt62::aux::stream_provider<char>::stream_compound *)" (?release_compound#?$stream_provider#D#aux#v2s_mt_nt62#log#boost##SAXPAUstream_compound#12345##Z)
1>Logging.obj : error LNK2019: unresolved external symbol "public: static void * __cdecl boost::log::v2s_mt_nt62::attribute::impl::operator new(unsigned int)" (??2impl#attribute#v2s_mt_nt62#log#boost##SAPAXI#Z) referenced in function "class boost::log::v2s_mt_nt62::attribute_value __cdecl boost::log::v2s_mt_nt62::attributes::make_attribute_value<unsigned int &>(unsigned int &)" (??$make_attribute_value#AAI#attributes#v2s_mt_nt62#log#boost##YA?AVattribute_value#123#AAI#Z)
1>Logging.obj : error LNK2019: unresolved external symbol "public: static void __cdecl boost::log::v2s_mt_nt62::attribute::impl::operator delete(void *,unsigned int)" (??3impl#attribute#v2s_mt_nt62#log#boost##SAXPAXI#Z) referenced in function __unwindfunclet$??$make_attribute_value#AAI#attributes#v2s_mt_nt62#log#boost##YA?AVattribute_value#123#AAI#Z$0
Edit: I also wanted to mention my preprocessor variables for Debug/Win32
WIN32
_DEBUG
_CONSOLE WIN32_LEAN_AND_MEAN
_WIN32_WINNT=0x0A00
I haven't been able to find a _WIN32_WINNT value for Windows 11, and I thought maybe that could be the problem. But I'm not entirely sure that matters.
The problem is that Boost, and Boost.Log in particular, was built for a different Windows version. You need to either:
Build Boost with _WIN32_WINNT defined to the same version as you define when you build your code.
Define BOOST_USE_WINAPI_VERSION when building your code to the Windows version Boost should target, which would be lower than your _WIN32_WINNT. Also define _WIN32_WINNT or BOOST_USE_WINAPI_VERSION macro to that version when building Boost.
To define the macro when building Boost add define=macro=value to the b2 command line. For example, define=_WIN32_WINNT=0x0A00.
I am working with visual studio 2012 to compile LuaJava. The problem I am having is when I call the linker. The line that calls the linker in the makefile is:
link /dll /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64"
/LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64"
/out:luajava-1.1.dll src\c\luajava.obj
"C:\Program Files (x86)\Lua\5.1\lib\lua5.1.lib" /VERBOSE
This seems to almost be linking everything successfully, until it gets to the Lua library.
The linker outputs the following when I try to make the project:
...//linking of other libraries
Finished searching libraries
Unused libraries:
C:\Program Files (x86)\Lua\5.1\lib\lua5.1.lib
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64\OLDNAMES.lib
luajava.obj : error LNK2019: unresolved external symbol lua_close referenced in function Java_org_keplerproject_luajava_LuaState__1close
luajava.obj : error LNK2019: unresolved external symbol lua_newthread referenced in function Java_org_keplerproject_luajava_LuaState__1newthread
luajava.obj : error LNK2019: unresolved external symbol lua_gettop referenced in function Java_org_keplerproject_luajava_LuaState__1getTop
...//lots of these errors
luajava-1.1.dll : fatal error LNK1120: 88 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\BIN\x86_amd64\link.EXE"' : return code '0x460'
Stop.
I'm confused as to why it says that the Lua library is unused, and then complains when it can't find the Lua library functions.
You can not link a 32 bit library to your 64 bit application. After some searces I do not believe LuaJava has a x64 download so to use this you must change your application to 32 bit.
Edit:
A second method would be to recomile LuaJava as a 64 bit dll. Here is a very recent post about that: LuaJava compile error "Unresolved external symbol"
Summary: Is there any tiny example on how to build the Win32 C++ console application that uses the libgit2 library (sources available at GitHub)?
I have followed the readme and the wiki on how to build the library on Windows using the CMake, and it worked smoothly (only a single unit-test error).
Now, I want to build a simple console application that uses the library -- using Microsoft Visual Studio C++ 2010 (the.vcxproj and the.sln). I have found the general.c code in the libgit2 examples, and I would like to do the same from my C++ application. No success -- I feel really stupid today...
I have noticed there is libqgit2 for C++ and Qt. Is there anything similar for pure C++? Or is there a way to use the C library from C++ application?
Update: I have renamed the general.c to general.cpp, added the libgit2 include path to the project and the path to the .lib files, changed the #include <stdio.h> to #include <cstdio>, and compiled. The following link errors appear:
1>------ Build started: Project: libgit2_general, Configuration: Debug Win32 ------
1>general.obj : error LNK2019: unresolved external symbol _git_repository_free referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_config_get_string referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_config_get_int32 referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_config_open_ondisk referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_strarray_free referenced in function _main
... etc.
1>general.obj : error LNK2019: unresolved external symbol _git_repository_open referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _giterr_last referenced in function "void __cdecl check_error(int,char const *)" (?check_error##YAXHPBD#Z)
1>D:\Tutorial\libgit2_general\Debug\libgit2_general.exe : fatal error LNK1120: 56 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This strongly suggests a calling convention mismatch to me. libgit2 uses __stdcall by default, for a number of reasons, while Visual Studio defaults to creating projects that use the __cdecl calling convention. While your program can use either calling convention and successfully call libgit2 using a different one, the easiest solution is probably just to use the same calling convention for both.
When you configure libgit2, you can turn off the STDCALL flag, which will cause it to emit a library built with __cdecl calling conventions:
cmake %PATH_TO_LIBGIT2_SOURCE% -DTHREADSAFE=ON -DSTDCALL=OFF
cmake --build .
It's a little surprising if you generated the project from CMake, bit it could be that you're not linking to libgit2.lib. Make sure you have git2.dll in Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies.
I am having a hard time trying to use yaml-cpp 0.3.0 on my project
I downloaded yaml, and built it like http://code.google.com/p/yaml-cpp/ said, with VS 9 2008 WIN 64. So, i got the yaml-cpp.dll and the yaml-cpp.lib
I have a c++ project on VS 2010 express, and i am trying to link the library:
I go to project properties - c/c++ general and additional include directories that have yaml-cpp header files. Then i go to linker and add path to my lib directory, then I go to linker - input and add my .lib file, then i go to VC++ Directories and add path to my lib directory in Library directories and Reference directories
Then i try to build this simple code:
std::ifstream fin("test.yaml");
YAML::Parser parser(fin);
YAML::Node doc;
while(parser.GetNextDocument(doc)) {
//do nothing yet
}
I got several linking problems, like this:
error LNK2019: unresolved external symbol "public: __thiscall YAML::Node::Node(void)" (??0Node#YAML##QAE#XZ) referenced in function "public: __thiscall Parser::Parser(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Parser##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
error LNK2019: unresolved external symbol "public: __thiscall YAML::Parser::~Parser(void)" (??1Parser#YAML##QAE#XZ) referenced in function "public: __thiscall Parser::Parser(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Parser##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
Can anyone help me? I am banging my head against a wall here.
As you said you've got a DLL from YAML, I assume you specified -DBUILD_SHARED_LIBS=ON when you built with VS2008, so you ended up with a lib for dynamic linking (to the DLL at runtime) rather than static linking (at compile time).
If the above is correct, it may be differences between VS2008 and VS2010 that are causing a problem. For example, see this post here. To quickly see if this is the cause, in your VS2010 project properties, set the Platform Toolset to V90 and see if that helps.
Also, make sure you compiled both projects for the same CPU - i.e. both for 32-bit or both for 64-bit.
I am trying to recompile some code I have for a new system. It involves a precompiled static library that I do not have the source code for (just the header), and this library was built with VC++ 6.0 or older with the older runtime libraries. On my old system, which had VC++ 6.0, my program was built and ran fine, but I have recently upgraded things and I no longer have access to VC++ 6.0, only Express 2008 (9.0 w/ SP).
When I build the solution, it compiles but has the following linker error:
1>libcpmtd.lib(xlock.obj) : error LNK2005: "public: __thiscall
std::_Lockit::~_Lockit(void)" (??1_Lockit#std##QAE#XZ) already defined
in NOREC.lib(track.obj) 1>LIBCMT.lib(stdexcpt.obj) : error LNK2005:
"public: __thiscall std::bad_cast::bad_cast(char const *)"
(??0bad_cast#std##QAE#PBD#Z) already defined in NOREC.lib(track.obj)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall
std::bad_cast::bad_cast(class std::bad_cast const &)"
(??0bad_cast#std##QAE#ABV01##Z) already defined in
NOREC.lib(track.obj) 1>LIBCMT.lib(stdexcpt.obj) : error LNK2005:
"public: virtual __thiscall std::bad_cast::~bad_cast(void)"
(??1bad_cast#std##UAE#XZ) already defined in NOREC.lib(track.obj)
1>LINK : fatal error LNK1104: cannot open file 'libcp.lib'
Any ideas how to overcome this issue would be very welcome.
From the last link error, libcp.lib cannot be found. This library has been removed as of VS 2005. Use /MT for the multithreaded version.
http://msdn.microsoft.com/en-us/library/abx4dbyh%28v=vs.80%29.aspx
The multithreaded version is libcpmt.lib which you will get automatically with the /MT flag. I see in the first error you are using libcpmtd.lib which is the debug version of the same. I'm not sure how you are getting that if you are not using /MTd. (or if you are, how libcp.lib is referenced since you should be using one or the other, not both)
The linker is telling you that some symbols are defined more than once. The brute force to convice the linker to produce your target image is to use the /FORCE:MULTIPLE as explained here. I used to use this switch a few times.
LINK : fatal error LNK1104: cannot open file 'libcp.lib'
This is a bug in the linker. Just create an empty file named libcp.lib in the LIBPATH.
libcp.lib you can find in installed MS Visual Studio 6.0 in
c:\Program Files\Microsoft Visual Studio\VC98\Lib\
directory.
Just copy it to your MSVS 2005/2008/2010 lib directory
(i.e. c:\Program Files\Microsoft Visual Studio 8\VC\lib\)
And everything will compiled just fine.