Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include source code written in C from another project into my own project in C++ in Visual Studio

I want to use Potrace for a C++ project on Windows in Visual Studio, but I have no clue of how to include Potrace into my project. I have tried to compile the C files using Cygwin, and that way create an .a file and then link to it in visual studio, but that didn’t work. Visual Studio were able to recognize the the functions from Potrace, but when running a test program with Potrace(Calling potrace_version() ), Visual Studio got the error “LNK2019 unresolved external symbol _potrace_version referenced in function_main”

I have gotten it to work on Ubuntu by using the technique mentioned above, and then compiling my code with: g++ main.cpp backenddxf.cpp ImageManipulation.cpp ./libubuntu/libpotrace.a -o test.out 'pkg-config --cflags --libs opencv

Do I have to compile the source code(Called “source distribution” on the website) to a lib file, and then link it to my project, in that case, how do I do so? Or is there something I have missed. I am using Visual Studio 2017 on Windows 10.

I am not to proficient in the workings of C++ so a detailed explanation is greatly appreciated.

like image 600
Leblarh Avatar asked Mar 09 '18 08:03

Leblarh


1 Answers

I got it working using this answer by Yaakov to compile potrace to an .a file

./configure --prefix=/usr/x86_64-64-ming32/sys-root/mingw --host=x86_64-w64-mingw32 --with-libpotrace

and then

make

Afterwards I used this answer by Stuti Rastogi on how to link the .a file in Visual Studio.

like image 152
Jakob Andersen Avatar answered Nov 03 '22 23:11

Jakob Andersen