QuantLib Date class in Visual C++ 2010 - visual-studio-2010

I just started this simple Quantlib date class in VC++ Express 2010:
#include <iostream>
#include <sstream>
#include "ql/time/date.hpp"
int main(int, char* [])
{
QuantLib::Date d(1, QuantLib::January, 2010);
std::cout<<da<<std::endl;
}
When I compiled it, this is one of the errors:
1>ql_inout.obj : error LNK2019: unresolved external symbol "public: __thiscall QuantLib::Date::Date(int,enum QuantLib::Month,int)" (??0Date#QuantLib##QAE#HW4Month#1#H#Z) referenced in function _main
It must be something I didn't setup correctly in 2010 project. I have compiled the library in Debug mode successfully.

Not all headers include the pragma that tells the linker to add QuantLib. If you don't want to include the full headers—which is advisable, as they would increase a lot your compilation time—you can add
#include <ql/auto_link.hpp>
to the included headers.
(You could also add the library explicitly to the linker options, but that is a lot more work since you have to specify different library names depending on the configuration. auto_link.hpp does this for you.)

Related

Using minGW to create a static library for use with Intel Fortran

Let me start off by stating that I am not a programmer. I am a Mech Eng that has to use code from various other engineers and assemble them into an executable. The main code is fortran and is compiled using Intel Fortran via Visual Studio 2008 (yes, very old version). One of the supporting codes is c++. Normally, I compile the c++ code using the built in Visual c++ compiler into a static lib then link the static lib into the main fortran code. The latest update of the c++ code will not compile in the 2008 Visual c++ because it needs the /permissive option. So, I have tried to get the c++ code compile into a static lib using g++. I get unresolved external symbol errors when doing this. The c++ code I use it very complex so I decided to make a simple example to see if I could get that to work. I am getting similar errors but since it is so simple I can post it here.I am sure someone on this forum can fix it in a few min. Here is the example c++ code:
#include <fstream>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
//------------------------------------------------------------------------
extern "C"
{
void add_2_nums(double *x,double *y,double *z);
}
extern "C" void add_2_nums(double *x,double *y,double *z)
{
*z = *x + *y;
return;
}
I compiled it using both g++/ar and mingw32-g++/mingw32-gcc-ar. Here is an example command:
mingw32-g++ -s -Iincludem -Iincludev -c -O2 -DNDEBUG add_2_nums.cpp
mingw32-gcc-ar r add_2_nums.lib add_2_nums.o
Some of the compiler options I used was from this forum in trying to resolve the errors and may not be appropriate.
Here is the simple fortran code:
program gcc_fun
implicit none
! Variables
real*8 x,y,z
x = 3.d0
y = 17.d0
call add_2_nums(x,y,z)
! Body of gcc_fun
print *, 'Z = ', z
end program gcc_fun
I use the C,Reference compile option and the rest default inside the Visual Studio environment. Here are the errors I get:
Error 1 error LNK2019: unresolved external symbol __ZNSt8ios_base4InitD1Ev referenced in function ___tcf_0 add_2_num.lib(static_lib_test.o)
Error 2 error LNK2019: unresolved external symbol __ZNSt8ios_base4InitC1Ev referenced in function __GLOBAL__sub_I_add_2_nums add_2_num.lib(static_lib_test.o)
Error 3 fatal error LNK1120: 2 unresolved externals Debug\gcc_fun.exe

Call unmanaged g++ .lib in C++/CLI

is it possible to wrap a static library which was compiled using g++ in C++/CLI?
Here is my try:
Unmanaged C++
#include <string>
class Person
{
public:
Person(void);
~Person(void);
void Print(std::string, std::string);
};
C++/CLI
#pragma once
#include <Person.h>
#pragma comment (lib, "VS-Person.lib")
//#pragma comment (lib, "GPPPerson.lib")
namespace CppWrapper {
public ref class PersonWrapper {
private:
Person* m_person;
protected:
public:
PersonWrapper(); // Doing 'm_person = new Person();'
~PersonWrapper();
};
}
The think is, when using the lib compiled in a VS2010 solution (VS-Person.lib), it works perfectly but when using the lib compiled with g++ (GPPPerson.lib), I got the following errors:
error LNK2028: jeton non résolu (0A00032D) "public: __thiscall Person::Person(void)" (??0Person##$$FQAE#XZ) référencé dans la fonction "public: __clrcall CppWrapper::PersonWrapper::PersonWrapper(void)" (??0PersonWrapper#CppWrapper##$$FQ$AAM#XZ)
error LNK2019: symbole externe non résolu "public: __thiscall Person::Person(void)" (??0Person##$$FQAE#XZ) référencé dans la fonction "public: __clrcall CppWrapper::PersonWrapper::PersonWrapper(void)" (??0PersonWrapper#CppWrapper##$$FQ$AAM#XZ)
Did I miss something?
How can I wrap an unmanaged library compiled with g++ in C++/CLI?
Thanks,
It's not possible. G++ and Visual C++ have wildly different expectations about object/library files. It's possible to recompile the unmanaged portion in Visual C++ and link to that.
Alternatively, you can build a DLL in G++ and P/Invoke that from C++/CLI.
EDIT: since it's a C++ library (as opposed to C), doubly impossible. G++ and Visual C++ won't agree on name mangling; so none of the C++ symbols would match upon linking/dynamic loading.
That said, why are you doing this in the first place? Mixing coding paradigms (managed and unmanaged, in your case) within one module is a bad idea in general. Is it really about the Person class? While I won't deny that unmanaged C++ has its charms, mixed mode projects have no charm at all.

LNK2019: unresolved external symbol error in Visual Studio C++

This is my code in Visual Studio C++
#include "stdafx.h"
#include<opencv\cv.h>
#include<opencv\highgui.h>
using namespace cv;
int main(int argc, char** argv[]) {
IplImage* img = cvLoadImage("logo.jpg");
cvNamedWindow("Test", CV_WINDOW_AUTOSIZE);
cvShowImage("Test", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Test");
return 0;
}
I am using OpenCV 2.4.6 and Visual Studio 2010. This is the error:
openCV_testing.obj : error LNK2019: unresolved external symbol _cvDestroyWindow
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvReleaseImage
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvWaitKey referenced in
function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvShowImage referenced
in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvNamedWindow
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvLoadImage referenced
in function _main
Please help.
'unresolved external symbol' means that you're not linking with required library.
Go to Properties -> Linker -> Additional Library dependencies and add path to OpenCV libs.
First check
How to build applications with OpenCV inside the Microsoft Visual Studio
If you still suffer from the same problem, you could be under one of the below cases.
Your active solution platform is x86 but you are trying to link x64 OpenCV libraries.
Your active solution platform is X64 but you are trying to link x86 OpenCV libraries.
If you are under one of these cases, check
Compiling a 64-bit Application in Microsoft Visual Studio Express 2010
Add these into your code:
#pragma comment (lib, "opencv_core248d.lib")
#pragma comment (lib, "opencv_highgui248d.lib")
#pragma comment (lib, "opencv_imgproc248d.lib")
#pragma comment (lib, "opencv_video248d.lib")
#pragma comment (lib, "opencv_features2d248d.lib")
It worked for me.
i searched a lot for the same problem this was the best solution i had found and it worked for me.
Open Configuration Properties > C/C++ > General, and edit the field Additional Include Directories to add these 3 paths (for the headers):
C:\OpenCV2.3\build\include\opencv
C:\OpenCV2.3\build\include\opencv2
C:\OpenCV2.3\build\include
I know this is not about the OpenCV library, but I already had a problem importing Tiny-Process library. My .lib file was linked correctly in Configuration Properties -> Linker -> Additional Library dependencies and the Additionnal Include Directories were correctly added but the the functions definition (s) were still not found and I was getting the LNK2019 error.
To fix the issue, I had to go in the library project properties, change the Character Set property in Configuration Properties -> Advanced Character Set and change the value Use Multi-Byte Character Set to Use Unicode Character Set.
After recompiling the library and using the new .lib file, it was working.

error LNK2019: unresolved external symbol - only .h files

Argh... I've been struggling lately to make Visual Studio 2010 (VC++) include a bunch of 3rd party libraries I wanna use in my project. That's the issue: The linker seems not to be able to determine every symbol that is generated in my code which come from the 3rd party libraries definitions. I've included the header files path on my include directories and also the sources path on my source directory, but it is still not working. I've googled it for a while and in most of cases, the issues is cause by a missing reference of the .lib file on linker's additional dependencies, however the library don't come with them.
Here's a piece of sample code:
#include "stdafx.h"
#include <fuzzylite\FuzzyEngine.h>
int _tmain(int argc, _TCHAR* argv[])
{
fl::FuzzyEngine eng;
return 0;
}
So that's the output VS shows
Fuzzycolors.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall fl::FuzzyEngine::~FuzzyEngine(void)" (??1FuzzyEngine#fl##UAE#XZ) referenced in function _wmain
Fuzzycolors.obj : error LNK2019: unresolved external symbol "public: __thiscall fl::FuzzyEngine::FuzzyEngine(void)" (??0FuzzyEngine#fl##QAE#XZ) referenced in function _wmain
So i wonder if is there a way to build my sources with the .h and .cpp files of my 3rd party library.
Thank you.
Caio
Check the new version of fuzzylite-2.0 at http://www.fuzzylite.com. That problem has been solved.
Windows requires to add __declspec(dllexport) to classes, which was not present in previous versions. Today, every class starts with class FL_EXPORT Engine, where FL_EXPORT is the missing definition.

Having problems linking with v8 on windows

I'm using Visual Studio 2010 on a 64-bit Windows 7 machine. I've pulled v8 source from SVN, built it with no problems (wich arch=x64), but I still can't compile my project that tries to use v8.
Here is a sample code that produces that same error :
#include <v8.h>
int main(int argc, char *argv[])
{
v8::Handle<v8::Context> context = v8::Context::New();
return 0;
}
The linker error I get is :
v8test.obj : error LNK2019: unresolved external symbol "public: static class v8::Persistent<class v8::Context> __cdecl v8::Context::New(class v8::ExtensionConfiguration *,class v8::Handle<class v8::ObjectTemplate>,class v8::Handle<class v8::Value>)" (?New#Context#v8##SA?AV?$Persistent#VContext#v8###2#PAVExtensionConfiguration#2#V?$Handle#VObjectTemplate#v8###2#V?$Handle#VValue#v8###2##Z) referenced in function _main
I built v8 as a static lib, tried both debug and release build, I get the same error.
In addition to v8_base.lib you need to also include v8_snapshot.lib, ws2_32.lib, and winmm.lib.
The sample on the V8 Getting Started Page can be compiled in a Console Application with following dependencies listed under Project Properties->Configuration Properties->Linker->Input->Additional Dependencies:
v8_base.lib;v8_snapshot.lib;ws2_32.lib;winmm.lib;(AdditionalDependencies)

Resources