I realise this i mighty popular question, but all of the other posts seem to follow the same idea. That the include, lib and bin folder need to be correctly configured. I believe my settings are correct, but i am still getting the LNK2019 error. What am i doing wrong?
Using Visual Studio 2012
I am getting the infamous LNK2019 error. Many posts of this issue seem to think it is a linker issue. I am using a library with lib and dll files. The project folder has an include, bin and lib folder that need to be configured in the project.
Install instructions are here.....
http://opensource.mlba-team.de/xdispatch/docs/current/tutorial.html
However, this is clearly a linker issue as it occurs in other libraries of a similar type. I have followed the instructions for other posts and i'm still a bit lost. I believe this should be correct, but i have tried virtually every possible combination. Don't get it.
My Project Configurations
C++ -> General -> Additional Include Directories.
C:\Users\Daniel\Documents\Visual Studio 2012\Projects\LibDispatchTest\xdispatch_0.7.2_Visual Studio 10_i386\include;%(AdditionalIncludeDirectories)
Linker -> General -> Additional Library Directories
C:\Users\Daniel\Documents\Visual Studio 2012\Projects\LibDispatchTest\xdispatch_0.7.2_Visual Studio 10_i386\lib;%(AdditionalLibraryDirectories)
Linker -> Input -> Additional Dependancies:
.....uuid.lib;odbc32.lib;odbccp32.lib;xdispatch.lib;%(AdditionalDependencies)
Environment Variables.
I have the PATH variable set.
C:\Chocolatey\bin;C:\Users\Daniel\Documents\Visual Studio 2012\Projects\VisionBase\xdispatch_0.7.2_Visual Studio 10_i386\bin;
The error messages are:
error LNK2019: unresolved external symbol "_declspec(dllimport) public: void __thiscall xdispatch::queue::async(class std::function<void __cdecl(void)> const &)" (__imp?async#queue#xdispatch##QAEXABV?$function#$$A6AXXZ#std###Z) referenced in function "void __cdecl some_function(void)" (?some_function##YAXXZ) c:\Users\Daniel\documents\visual studio 2012\Projects\LibDispatchTest\LibDispatchTest\main.obj LibDispatchTest
error LNK1120: 1 unresolved externals c:\users\daniel\documents\visual studio 2012\Projects\LibDispatchTest\Debug\LibDispatchTest.exe 1 1 LibDispatchTest
Seriously, am totally lost and i do not see what i am doing wrong here.
EDIT 1
This is similar to a sample from the above link, but modified to just couNT 1000000^2 and print some stuff. We just want to be able to compile and run this sample and i can correct my larger project exhibiting this issue. This project was made fresh with the simplest code that is representative of what i need to get working. Both this sample and my other project have this problem and produce the same error.
#include <xdispatch/dispatch>
#include <vector>
#include <cmath>
class SomeData {
public:
std::vector<double> a;
std::vector<double> b;
std::vector<double> c;
std::vector<double> results;
};
void do_calculations(SomeData* sd){
// our output will go in here
sd->results = std::vector<double>(sd->a.size());
// the calculation - running on one thread only
for(unsigned int i = 0; i < 1000000; i++){
sd->results[i] = 0;
for(unsigned int j = 0; j < 10000000; j++){
for(unsigned int z = 0; z < sd->c.size(); z++){
std::cout << i << " " << j << std::endl;
}
}
} }
/* This function is getting called from your main thread also powering the user interface */
void some_function() {
SomeData* sd = new SomeData();
xdispatch::global_queue().async(${
// execute the heavy code
do_calculations(sd);
}); }
int main() {
some_function();
return 0; }
Is anyone able to help?
The binaries you used where built with and for MS Visual Studio 2010. Since then the CRT has changed quite a bit and might not be compatible, especially when parts of the STL is used. Because of that I do not recommend to ever use a C++ dll built with VS 2010 for use in VS 2012 or later. It could be that building and linking succeeds but during runtime you experience weird and unexpected issues. In your case even linking won’t work because std::function has changed its signature in the meantime, so lucky enough you already discover those incompatibilities at compile time.
I assume xdispatch will work just fine with VS2012 and maybe even VS2013, however you will need to do your own build for that. All information needed is summarized at [1]. A tarball containing the sources can always be found at [2].
[1] http://opensource.mlba-team.de/xdispatch/docs/current/requirements.html
[2] http://opensource.mlba-team.de/xdispatch/files/
Related
I had a solution named fun.sln with a project called fun.vcxproj.
I created a whole bunch of name spaces ready to be used.
I made another project called no_more_fun.vcxproj.
I added the includes directory for fun.vcxproj to the configuration of no_more_fun.vcxproj.
I added this to no_more_fun.cpp
#include "candy.h"
void main(void)
{
candy::get();
return;
}
candy.h is in the default directory for fun.vcxproj(which was added to the config)
But I get...
LNK2001 unresolved external symbol "int __cdecl candy::get(unsigned long)" (?get#candy##YAHK#Z) .....
Visual Studio shows no error before compiling.
The "candy" namespace works fine in the "fun" project so idn...
Is there a guide or something so that i can understand how i can go about sharing code efficiently among different projects within ONE solution?
This is a linker error. You didn't get any error at compile time, because the compiler found the candy::get() method in candy.h header, but the implementation (which I suppose is in a candy.cpp file) is not found by the linker.
Just add candy.cpp too to no_more_fun.vcxproj.
ps. I didn't observe but in the error message you can see that the function waits a parameter.
call it like this:
unsigned long foo = 0;
candy::get(foo);
This is going to sounds stupid but...i just dragged the files in to visual studio so that the no_more_fun project had the "files" in its "directory" too.
wow... I shouldn't need to do that...Am I wrong?(sarcasm).
I'm very new to using visual studio, and c++.
I was trying to build a game to test my OOP understandings using new language, then I realized I might need to start using scripting language with in my C++ game. I found LUA to be a good candidate for the scripting part of the game, so I decided to follow a tutorial I've found at :
http://www.gamedev.net/page/resources/_/technical/game-programming/the-lua-tutorial-r2999
#include "stdafx.h"
#include <lua.hpp>
#include<iostream>
int main()
{
char *Lua =
"x = 8 "
"return ( x > 7 ) ";
lua_State *luaState;
luaState = luaL_newstate();
int iStatus = luaL_loadstring(luaState, szLua);
if (iStatus)
{
std::cout << "Error: " << lua_tostring(luaState, -1);
return 1;
}
return 0;
}
However VS 2015 debugger is giving
unresolved external symbol _luaL_newstate
unresolved external symbol _luaL_loadstring
unresolved external symbol _lua_tolstring
I'm currently using Lua 5.1.5, and followed the tutorial setting tutorial section step by step, where it tells me to add lua folders to project settings.
Can someone tell me what i'm doing wrong?
The linker errors indicate that you are missing Lua functions from the executable you want to build. It's possible that you missed this step in the tutorial you've been following: add the Lua source files to your project's "Source Files". There is a list of the files in C:\dev\lua-5.1.5\etc\all.c; you want all of those files except for lua.c.
In general, you need to add the Lua library, lua DLL, or Lua files (in this case it's not enough to specify path to them), so that the references for the functions you are using in your code are properly resolved (statically or dynamically).
In visual studio 2012 I have a small console c++ project with the following code
Main.cpp:
#include "../TestLib/LibFunction.h"
int _tmain(int argc, _TCHAR* argv[])
{
int number = libFunction(7);
return 0;
}
and in a static library project LibTest I have
LibFunction.h:
#pragma once
int libFunction( int a );
LibFunction.cpp
int libFunction( int a )
{
return a + 1;
}
This compiles and runs fine. (The Library is added as a reference and linked in implicitly)
If I now add this code to main project
int libFunction( int a )
{
return 7 * a;
}
when I try to build the program I get this error
Main.obj : error LNK2005: "int __cdecl libFunction(int)" (?libFunction##YAHH#Z) already defined in TestLib.lib(LibFunction.obj)
which is fair enough. However if I now just try building again ( doing nothing else ) the link completes without error and the program runs fine with the new libFunction being used.
Why does the error go away?
Why is there this inconsistency? Either it is valid to override a function in a library or its not. I should not get an error and then without doing anything get no error.
I am trying to understand the behaviour for a much larger project where again there are duplicate symbols defined in the exe and referenced lib and sometimes I get errors and sometimes not.
Normally it should be OK to override library symbols. There are still caveats; for instance, if library code contains several external functions in the same source file, and you want to override one of them, you may have to override all the others. Otherwise you will get the multiple definitions error. But in this case you will get it consistently.
However such overrides may throw off the incremental linker, especially if it's the first build with the override. A full rebuild should be enough to correct the error until you add more overrides. If this is a problem, just disable incremental linking.
I have recently updated to Visual Studio 2013, and to avoid the known problems with uninstalling one of the two programs (I previously used 2010) while the other is installed I uninstalled 2010 before I installed 2013.
Despite what code I place in it, even simple code that is only a few lines, Everything gets this LNK2019 error.
#include<iostream>
using namespace std;
int main()
{
cout << "Testing" << endl;
system("pause");
return 0;
}
Before anyone comments with the "Do not use system("pause")" I know this and I did it purely for simplicity reasons to see if the code would even compile as it would not with any of my longer code either.
Here is a copy of the Error message.
Error 1 error LNK2019: unresolved external symbol WinMain#16 referenced in >function __tmainCRTStartup C:\Users\z49203\Documents\Visual Studio >2013\Projects\JCCNEW\JCCNEW\MSVCRTD.lib(crtexew.obj) JCCNEW
As for extensions in Visual Studio, I have the English version of it with the Japanese language pack. As I need to be able to code using both character sets.
Make your project a Console application not a Window Form one. Otherwise the program needs a WinMain as entry point instead of main.
I created a standard windows application with VS 2012 Pro. Just a main.cpp that looks like this:
#include "gdal_priv.h"
#include "cpl_conv.h"
int main(int argc, char* argv[])
{
GDALAllRegister();
return 0;
}
I have set my include path properly. I have gdal_i.lib in my Linker -> Input -> Additional Dependencies.
Link fails with the following message:
1>main.obj : error LNK2019: unresolved external symbol
_GDALAllRegister#0 referenced in function _main
(A scad of other symbols are missing as well, but this one should be easy.)
I used dumpbin and GDALAllRegister appears in the exported symbols. It does appear as "GDALAllRegister", not as "_GDALAllRegister#0".
I tried downloading and using the dev build, and also built myself. Same results.
I just know this is something simple, but I'm totally brain-cramping here. What have I done wrong?
Thanks.
-reilly.
I said it was simple and stupid, and it was.
I had the build manager set to build 32 bit.
Another 4 hours of my life I'll never get back.
Thanks to Manuell for his suggestion. It got me looking in a different direction and I found it.
Sorry, community. This is what comes from programming tired.
-reilly.
This kind of error is typical of a "Calling Convention" mismatch between EXE and LIB.
Check you have __cdecl (/Gd) in "Configuration Properties" -> C++ -> Advanced -> "Calling Convention"