Libraries

This question is bothered me alot. how i can use libraries in visual c++ 2012
i got alglib library http://www.alglib.net/ for example please i need an explanation step by step how i can put this functions into use
thanx alot

??
Just put all the includes and cpp files that are part of alglib in the same folder as the rest of your code. You might could put them in a folder of their own, but I did not try that. The example below is what I did with just copying ap.h, ap.cpp, and stdafx.h into the same directory as main.cpp. Then I just compiled them as seperate object files and linked the two together.
1
2
3
4
5
6
7
8
9
10
//main.cpp
#include <iostream>
#include "ap.h"

int main(int argc, char **argv)
{
    std::cout << "alglib::randomreal() - returns random real number from [0,1)"
              << std::endl << alglib::randomreal() << std::endl;
    return 0;   
}
Last edited on
1
2
3
4
5
6
7
8
9
10
#include "stdafx.h"
#include "ap.h"
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
	std::cout << alglib::randomreal();
	return 0;
}


Error 1 error LNK2019: unresolved external symbol "double __cdecl alglib::randomreal(void)" (?randomreal@alglib@@YANXZ) referenced in function _wmain

Error 2 error LNK1120: 1 unresolved externals

Last edited on
You need to link ap.cpp and main.cpp together

I did a simple compile and link like this:
> g++ -c ap.cpp
> g++ -c main.cpp
> g++ ap.o main.o

And on my system g++ makes a.exe by default if no -o switch is given, so I ran the code by doing this:
> a.exe
Last edited on
you need to tell Visual studio where to find the library files.

It's midnight here and I'm off but this may help:

http://msdn.microsoft.com/en-us/library/vstudio/ee855621.aspx
Topic archived. No new replies allowed.