0

I tried multiple PDF lybrary and MUPDF is my last chance to build my own small PDF application. But here I also have problems. Before that I had problem with LNK4098: defaultlib 'MSVCRT', but I solved that to set for all MUPDF library /MDd version. Most errors is solved after that, but still I can't to solve this:

error LNK2001: unresolved external symbol "void __cdecl pdfapp_open(struct pdfapp_s *,char *,int)" (?pdfapp_open@@YAXPEAUpdfapp_s@@PEADH@Z)
//more 3 errors

As MuPDF written on C, I do this:

extern "C" {
#include <pdfapp.h>
#include <mupdf\fitz\context.h>
}

But I get this errors:

error LNK2001: unresolved external symbol pdfapp_open
//more 3 errors

There is only three functions what I use in my application. I checked libs and headers linking, I set my project Debug, x64, /MDd also but I get the same. Honestly, I can't find this three functons in no one libs. I'm not a expert in programming but I know that functions strings should be finding in libs, doesn't? What does mean this errors in my case?

hardCode
  • 39
  • 6
  • 3
    C and C++ are different languages. They have a common subset large enough to write programs in, but programs not specifically written and maintained to comply with both standards are highly likely to be invalid in one language or the other. If you have a C library then build it with a C compiler. MSVC++ is not a conforming C compiler when running in C mode, and it *certainly* is not a conforming C compiler when running in C++ mode. Its C mode might be good enough to build your particular C code, however, especially if it's old code. – John Bollinger May 31 '17 at 15:49
  • @ John Bollinger I thought extern C must to solve any compatibility between C nand C++. (( Thanks for explanation. – hardCode May 31 '17 at 16:02
  • You already posted this question. It was a duplicate. While I don't have the permissions to view the old question, which you deleted, in case it was closed for being a duplicate, then posting the same question after it's been removed/closed will result in a ban or other punishment. – tambre May 31 '17 at 16:03
  • Sorry but it's new question with new issues, which is not duplicated. Indeed, my previous question was duplicated and was deleted. – hardCode May 31 '17 at 16:09
  • 1
    @hardCode, no, not at all. `extern "C"` expresses (in C++) that the function(s) so declared have *C linkage*. That makes it possible to link them to and call them from C, but it has nothing to do with their implementation, which must still be conforming C++ (since the `extern "C"` syntax is a C++-only feature). – John Bollinger May 31 '17 at 16:09
  • There are many solutions listed on that answer. It's an obvious duplicate. You're failing to link with a library that implements that method, thus the linker can't find the implementation of the method and linking fails. – tambre May 31 '17 at 16:24

1 Answers1

0

Either your linker is failing to find the import library for mupdf or you have a name mangling/decoration type issue.

Once you download and build mupdf, there should be an import library for you to link to. Are you linking to it? Look in your project linker settings under Linker >> Input >> Additional Dependencies. Have you added such an import?

If not, add it in. It shouldn't be hard to find. It is likely right next to the mupdf DLL that you downloaded (or built).

Assuming you have added it, your next step is to verify that you are properly finding it. Look at the build output. Are you getting a warning about it? No, change the Linker >> General >> Show Progress to "Display all progress messages" and build again. Is there a warning about the library or function?

Last possibility that I can think of is that the DLL is actually exporting its functions as C++ (i.e. with name decoration), not as extern "C". In that case and your extern "C" brackets don't belong there. Or perhaps vice versa (i.e. maybe you failed to use extern "C" in all places you #include it). I can see that your example uses it but is that all the places?

If you are building the mupdf.DLL be sure it is being built the same way and with the same calling convention as your client code.

Joe
  • 5,394
  • 3
  • 23
  • 54