I have installed libraries with vcpkg using the correct triplet :
C:\Users\***>vcpkg list libnoise
libnoise:x64-windows 1.0.0 A general-purpose library that generates three-d...
Then I have executed the following command :
C:\Users\***>vcpkg integrate install
Applied user-wide integration for this vcpkg root.
All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/Windows/vcpkg/scripts/buildsystems/vcpkg.cmake"
But in my Visual Studio 2019 project, with an x64 project, only the headers have been successfully integrated :
#include <noise/noise.h> // The header is found as well as the definition of noise::module::Perlin
int main()
{
noise::module::Perlin noise; // The implementation is not found
}
When trying to compile this, I get :
1>------ Build started: Project: Mayak, Configuration: Debug x64 ------
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl noise::module::Perlin::Perlin(void)" (__imp_??0Perlin#module#noise##QEAA#XZ) referenced in function main
1>NoiseVideoGenerator.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl noise::module::Perlin::Perlin(void)" (__imp_??0Perlin#module#noise##QEAA#XZ)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl noise::module::Perlin::~Perlin(void)" (__imp_??1Perlin#module#noise##UEAA#XZ) referenced in function main
1>NoiseVideoGenerator.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl noise::module::Perlin::~Perlin(void)" (__imp_??1Perlin#module#noise##UEAA#XZ)
1>C:\Users\sylva\source\repos\Mayak\x64\Debug\Mayak.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "Mayak.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
On a side note, I have looked for the name of the .lib files of the noise library and tried to add them in the Linker > Input properties, it still doesn't work.
What did I do wrong ?
To enable AutoLink, select your current project and go to properties. (Alt-Enter) Make sure you edit the right configuration. Then go to Configuration Properties -> vcpkg and make sure AutoLink is enabled.
It has been fixed by the developers, on GitHub : https://github.com/microsoft/vcpkg/issues/14127
Related
I've compiled the grpc library from source code using the official instructions on github.
I've used cmake to invoke MSVC v142 build tools(Visual Studio 2019), and generated two build configurations one for Release, and one for Debug.
From the build artifacts, and from the include files of the gRPC library, I've created a C++ NuGet package. That NuGet package uses both the Release as well as the Debug build artifacts(and of course places them in a designated folder for each configuration type).
I've created some "Hello World" app that consumes the gRPC library on Windows, via the NuGet package that I've built. (This is just a standard example the can be found on gRPC official examples, nothing new was added).
On Debug build of the "Hello World" app, everything works just fine - compilation, linking, execution and debugging, but when I switch to compile the project on Release, I have 7 linker errors related to missing functions definitions.
The instruction of how to build gRPC from source code was taken from here: "https://github.com/grpc/grpc/blob/master/BUILDING.md".
I've searched where were those functions implemented back on the gRPC source code, and found that it's in the 'grpc++' project, which being compiled to be 'grpc++.lib'. I've checked that this file does get included in my nuget package, in the correct configuration(Release) and architecture(x64).
I've checked that I did took the correct configuration and architecture as an input for the NuGet package, and even tried to link against those binaries directly without using the NuGet package that I've created.
This is the linker output when building with Release, x64:
1>------ Build started: Project: HelloGrpc++NuGet, Configuration: Release x64 ------
1>HelloWorldServer.cc
1>HelloWorldServer.obj : error LNK2001: unresolved external symbol "class std::shared_ptr<class grpc::ServerCredentials> __cdecl grpc::InsecureServerCredentials(void)" (?InsecureServerCredentials#grpc##YA?AV?$shared_ptr#VServerCredentials#grpc###std##XZ)
1>HelloWorldServer.obj : error LNK2001: unresolved external symbol "public: __cdecl grpc::ServerBuilder::ServerBuilder(void)" (??0ServerBuilder#grpc##QEAA#XZ)
1>HelloWorldServer.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl grpc::ServerBuilder::~ServerBuilder(void)" (??1ServerBuilder#grpc##UEAA#XZ)
1>HelloWorldServer.obj : error LNK2001: unresolved external symbol "public: virtual class std::unique_ptr<class grpc::Server,struct std::default_delete<class grpc::Server> > __cdecl grpc::ServerBuilder::BuildAndStart(void)" (?BuildAndStart#ServerBuilder#grpc##UEAA?AV?$unique_ptr#VServer#grpc##U?$default_delete#VServer#grpc###std###std##XZ)
1>HelloWorldServer.obj : error LNK2001: unresolved external symbol "public: class grpc::ServerBuilder & __cdecl grpc::ServerBuilder::RegisterService(class grpc::Service *)" (?RegisterService#ServerBuilder#grpc##QEAAAEAV12#PEAVService#2##Z)
1>HelloWorldServer.obj : error LNK2001: unresolved external symbol "public: class grpc::ServerBuilder & __cdecl grpc::ServerBuilder::AddListeningPort(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::shared_ptr<class grpc::ServerCredentials>,int *)" (?AddListeningPort#ServerBuilder#grpc##QEAAAEAV12#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$shared_ptr#VServerCredentials#grpc###4#PEAH#Z)
1>D:\Users\abiton\Desktop\grpcsandbox\HelloGrpc++NuGet\bin\x64\Release\HelloGrpc++NuGet.exe : fatal error LNK1120: 6 unresolved externals
1>Done building project "HelloGrpc++NuGet.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This is the executable code that uses the gRPC C++ library(Standard example, nothing was added by me):
#include <iostream>
#include <memory>
#include <string>
#include <grpc++/grpc++.h>
#include "src/server/helloworld.grpc.pb.h"
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using helloworld::HelloRequest;
using helloworld::HelloReply;
class GreeterServiceImpl final : public helloworld::Greeter::Service
{
Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* response) override
{
response->set_message("Hello from GRPC Server !");
return Status::OK;
}
};
int main(int argc, char** argv)
{
std::string server_address("0.0.0.0:50051");
GreeterServiceImpl service;
ServerBuilder builder;
// Listen on the given address without any authentication mechanism.
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
// Register "service" as the instance through which we'll communicate with
// clients. In this case it corresponds to an *synchronous* service.
builder.RegisterService(&service);
// Finally assemble the server.
std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl;
// Wait for the server to shutdown. Note that some other thread must be
// responsible for shutting down the server for this call to ever return.
server->Wait();
return 0;
}
These are relative paths for additional include directories added to my sample project:
grpc\include
grpc\third_party\protobuf\src
These are relative paths for the build artifacts:
grpc\.build\Release
grpc\.build\third_party\cares\cares\lib\Release
grpc\.build\third_party\protobuf\Release
grpc\.build\third_party\zlib\Release
And these are the linker inputs:
address_sorting.lib
cares.lib
gpr.lib
grpc.lib
grpc++.lib
grpc++_unsecure.lib
libprotobuf.lib
zlib.lib
Any help will be appreciated !
How do I link the library in a way that visual studio 2015 can actually see it?
Here's a few screenshot of my folders:
glfw3, glfw3/include/glfw/, glfw3/lib
I've attempted to link these folders into visual studio, under "vc++ directories => include/library directories as such: include, library
also linking the same to my project directly, under linker => input => additional dependencies
to me, that seems like everything is correct (this is how it was in the tutorial i am following, learnopengl.com)
note: I am also doing the same with the GLAD library, which that has a .c file that I put directly into my sources, along with the header files linked the same way as with GLFW.
but despite trying to run this code:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main() {
glfwInit();
return 0;
}
it will always return this error, or similar ones:
1>------ Build started: Project: opengl_test, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
1>C:\Users\Honza\Desktop\C++ programs\lib\glfw3\lib\glfw3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'
1>c:\users\honza\documents\visual studio 2015\Projects\opengl_test\Debug\opengl_test.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I'm guessing there is something wrong with how I linked the libraries. I am willing to literally re-install visual studio if I have to, just please give me some possible solutions. I want to start learning opengl but all this jazz with linking libraries is leaving me frustrated and confused.
EDIT: The problem here was that I was using 64-bit GLFW binaries instead of the 32-bit ones, and compiling in 32-bit. I've fixed that, and now I get even more errors:
1>------ Build started: Project: opengl_test, Configuration: Debug Win32 ------
1>libglfw3.a(init.c.obj) : error LNK2019: unresolved external symbol ___chkstk_ms referenced in function __glfwInputError
1>libglfw3.a(init.c.obj) : error LNK2019: unresolved external symbol _vsnprintf referenced in function __glfwInputError
1>MSVCRTD.lib(vsnprintf.obj) : error LNK2001: unresolved external symbol _vsnprintf
1>libglfw3.a(context.c.obj) : error LNK2019: unresolved external symbol _sscanf referenced in function __glfwRefreshContextAttribs
1>MSVCRTD.lib(vsnprintf.obj) : error LNK2001: unresolved external symbol __vsnprintf
1>C:\Users\Honza\Documents\Visual Studio 2015\Projects\opengl_test\Debug\opengl_test.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You write that you tried to link "these folders", while in fact, you need 2 separate things in order to use a function from a static library.
Use the proper header file so compilation succeeds. From the error you quoted, compilation went well. The program knows there is an external function named _glfwInit.
Link to the specific library (.lib file). Looks like you placed a path of a folder and not the full path of the .lib file.
Under Linker => input => additional dependencies, place the full path of the gfw3.lib file.
I faced the same problem while following learnopengl.com, The issue is that you need to rebuild glfw library with cmake again,
but this time when you choose visual studio 2015 or whatever for your generator for this project, you must also choose: OPTIONAL PLATFORM FOR GENERATOR -> x64
you can make sure that every thing is OK when you build glfw inside Visual Studio and the platform that appears is x64
all.
I’m compiling Ipopt-3.9.3 in Windows 10 & Visual C++ 2010 Express.
I’ve built the projects of libCoinBlas, libConHSL, libCoinLapack as well as libIpopt, and generated libCoinBlas.lib, libCoinHSL.lib, libCoinLapack.lib as well as libIpopt.lib in the correct paths but with some warnings.
While when I tried to build the projects of IpoptAmplSolver and hs071_cpp, there exists the following fatal errors.
5> Generating Code...
5> Creating library Release\IpoptAmplSolver.lib and object Release\IpoptAmplSolver.exp
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlr_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlr_
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlc_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlc_
5>dlascl.obj : error LNK2019: unresolved external symbol _disnan_ referenced in function _dlascl_
5>dpotf2.obj : error LNK2001: unresolved external symbol _disnan_
5>Release\IpoptAmplSolver.exe : fatal error LNK1120: 3 unresolved externals
========== Rebuild All: 4 succeeded, 1 failed, 0 skipped ==========
5>------ Rebuild All started: Project: hs071_cpp, Configuration: Release Win32 ------
5> hs071_main.cpp
5> hs071_nlp.cpp
5> Generating Code...
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlr_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlr_
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlc_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlc_
5>dlascl.obj : error LNK2019: unresolved external symbol _disnan_ referenced in function _dlascl_
5>dpotf2.obj : error LNK2001: unresolved external symbol _disnan_
5>LIBCMT.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
5>Release\hs071_cpp.exe : fatal error LNK1120: 4 unresolved externals
========== Rebuild All: 4 succeeded, 1 failed, 0 skipped ==========
Is there anyone who can kindly tell me how should I deal with it?
Thank you very much for your attention, and I’m looking forward to your kind aid.
Finally, I've solved this problem which is due to the undefined functions. I think my case is about a released software package rather than some specific procedure code, hence, it's a little different and relative simple.
Without knowing the specifics of the libraries you are using, I recommend that you try the following to deal with this error:
The error tells you that the linker is missing code for some function calls. This probably means that a library file is not found. Make sure that the linker can find all needed lib files. Check the property pages. Under the Linker->General->Additional library directories, make sure that the directories where your lib-files are located are present and under Linker->Input->Additional dependencies, make sure that the the lib-files are listed. Also make sure that the parameters are present for the different Configurations.
If this still does not help, check if your libraries depend on other libraries. These should be mentioned in the documentation of the libraries you are using.
I've not built this, but here's what I would try from the start. From what you've said, you've compiled the .lib files that it links against and it's failing during linking.
So here are your options...
1) You've either missed a .lib file in the input list for the linker.
2) The actual .lib file doesn't contain the symbol that the linker needs (you can check this by dumping the symbols of the .lib file)
3) Your .lib file is compiled with either the wrong platform than what you're linking with or with the wrong type ie. release/debug.
4) The symbols in your lib are decorated because you're compiling as C++ instead of C, or visa-versa.
If you go through the above steps above, I'm pretty sure you'll find your problem, but you've not really given enough information to properly answer your question. Personally, I'd have a guess that you're compiling C as C++ or you've got the wrong platform type set for one of your lib files.
Thank you all very much for your patient and detailed advices that inspired me, and I finally find out that I should add some C files which define the necessary functions into my project. The detailed solution is as follows.
For example, I want to eliminate
5>dlarf.obj : error LNK2019: unresolved external symbol _iladlr_ referenced in function _dlarf_
5>dlarfb.obj : error LNK2001: unresolved external symbol _iladlr_
Step 1: Run
f2c iladlr.f
In the Visual Stuido Command Prompt and generate iladlr.c.
Step 2: Add iladlr.c to my project.
Step 3: Rebuild.
Finally, everything goes well.
Following a complete reformat and an upgrade from Visual Studio 2012 to 2015, my program will not compile and spits linker errors at me. I have looked at the paths, linker and whatnot, and it looks just as it should for it to work, I have looked at my code as well in the referenced classes, but they are all set up with proper includes and namespaces too.
All files, including the SFML libraries and my own source code, was kept on my dropbox before i reformatted, so no files have changed folders, which i have double-checked as well.
Entire project is written in C++
1>------ Build started: Project: Starfall, Configuration: Debug x64 ------
1>AnimatedSprite.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class sf::RectangleShape & __cdeclsf::RectangleShape::operator=(class sf::RectangleShape &&)" (__imp_??4RectangleShape#sf##QEAAAEAV01#$$QEAV01##Z) referenced in function "public: __cdecl AnimatedSprite::AnimatedSprite(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct HandlerContainer *)" (??0AnimatedSprite##QEAA#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##PEAUHandlerContainer###Z)
1>DynamicSprite.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class sf::RectangleShape & __cdecl sf::RectangleShape::operator=(class sf::RectangleShape &&)" (__imp_??4RectangleShape#sf##QEAAAEAV01#$$QEAV01##Z)
1>CuboidDrawable.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class sf::ConvexShape & __cdecl sf::ConvexShape::operator=(class sf::ConvexShape &&)" (__imp_??4ConvexShape#sf##QEAAAEAV01#$$QEAV01##Z) referenced in function "public: __cdecl CuboidDrawable::CuboidDrawable(class CuboidShape,struct HandlerContainer *)" (??0CuboidDrawable##QEAA#VCuboidShape##PEAUHandlerContainer###Z)
1>C:\Users\Riilu\Dropbox\Starfall\Code and shit\Starfall\x64\Debug\Starfall.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Did you also upgrade SFML libraries to VS2015? Read here - "You must download the package that matches your version of Visual C++. ... If there's no SFML package compiled for your version of Visual C++, you will have to build SFML yourself"
The IDE I use is Visual Studio 2010 Professional, and the library I use is ICU4C 4.8.1 for Win32 for MSVC10.
I have rebuilt all the source codes according to the manual for both Debug and Release, and all tests are successfully passed.
Then I do in the way I do with Boost.
I included \include in C/C++ > Additional Include Directories in Proprieties, which seems to be fine.
I also included \lib in Linker > Additional Library Directories.
However, I keep getting error LNK2019: unresolved external symbol.
Source Code:
#include <unicode/uchar.h>
int main () {
UBool b = u_isprint('c');
return 0;
}
Error
1>ClCompile:
1> Main.cpp
1>Main.obj : error LNK2019: unresolved external symbol _u_isprint_48 referenced in function _main
1>C:\Users\ ... \Documents\Visual Studio\Finger-Printing-Non-ASCII\Debug\Finger-Printing-Non-ASCII.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
Apart from setting additional include directories and library directories, you have to actually link to the library. Go to Project Properties -> Linker -> Input and write the name to the .lib in Additional dependencies textbox. HTH