Menu

How can I include Potrace into my own project in C++ on Windows with Visual studio

Help
2018-03-09
2018-03-14
  • Jesper Ravn-Nielsen

    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.

     

    Last edit: Jesper Ravn-Nielsen 2018-03-09
  • Peter Selinger

    Peter Selinger - 2018-03-14

    Hi Jesper,

    I'm glad you were able to solve the problem. I have not encountered the LNK2019 error before, but it might be related to the difference between C and C++. They mangle the function names differently. Or maybe Visual Studio just didn't know where to find the .a file.

    For the record, on Windows 64-bit, when compiling with MinGW and then trying to use the libpotrace.a in Visual Studio, you can also sometimes get an LNK1223 error "file contains invalid .pdata contributions". This is related to the fact that gcc includes some optional data in the .a file in a format the Visual Studio doesn't like. Since the offending data serves no useful purpose in the first place, I was able to solve this problem by simply removing the .pdata section, with this command:

    objcopy --remove-section .pdata libpotrace.a

    -- Peter

     

Log in to post a comment.