Bug 691461 - Converting version 0.11 from C to C++ for use with MSVC++
Summary: Converting version 0.11 from C to C++ for use with MSVC++
Status: RESOLVED FIXED
Alias: None
Product: jbig2dec
Classification: Unclassified
Component: Build Process (show other bugs)
Version: master
Hardware: PC Windows 7
: P4 normal
Assignee: Ken Sharp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-15 14:27 UTC by Thomas Fobear
Modified: 2010-07-20 09:18 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
VS2008 Solution for JBig2Dec C++ (8.78 MB, application/x-zip-compressed)
2010-07-15 14:27 UTC, Thomas Fobear
Details
modified version of getopt.c (29.29 KB, text/plain)
2010-07-16 08:21 UTC, Ken Sharp
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Fobear 2010-07-15 14:27:08 UTC
Created attachment 6488 [details]
VS2008 Solution for JBig2Dec C++

A Visual Studio 2008 solution is included in the attachment. The environment is not set correctly for use with this configuration. The errors I am getting are in stdio.h -

error C3114: 'MustCheck': not a valid named attribute argument 
c:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdio.h	189
error C3114: 'Null': not a valid named attribute argument 
c:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdio.h	189
error C3114: 'Valid': not a valid named attribute argument 
c:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdio.h	189

I follow the error into "sal.h" the attribute arguments are surrounded by -

#ifdef _USE_ATTRIBUTES_FOR_SAL

when I add this to the command line -

/D "_USE_ATTRIBUTES_FOR_SAL=0"

it only generates different errors, something along the line of functions in stdio getting redifined with different linkage.

This is as far as I have gotten, any help on this issue is Mucho Apreciado.

-CodeBear
Comment 1 Ken Sharp 2010-07-16 08:21:15 UTC
Created attachment 6494 [details]
modified version of getopt.c

This is due to some weirdness in the MSVC stdio.h. The simplest way to 'fix' this that I've found is simply to define __STDC__ in the VS solution. This prevents the definition of 'const' which solves the problem. Another obvious solution would be to further guard the definition of const, which needs done in 2 files I think.

Right click the solution, select properties from the context menu. In the left pane click Configuration properties, then from the expanded tree click C/C++, select from the expanded tree the 'Preprocessor' item. In the right pane, under 'Preprocessor Definition' add __STDC__ (there will probably already be some definitions, use ; as a separator).

The next issue is that (as you already know) getopt.c uses K&R function declarations. I've attached a modified getopt.c which replaces these with ANSI definitions.

Then we have two 'main()' entry points, one in Main.cpp and one in jbig2dec.c. Since the one in Main.cpp doesn't do much I just removed it for now. You should probably remove jbig2dec.c since this is the command line code, presumably you will use this as a library.

The next problem is that it looks like jbig2dec relies on libpng in order to write the decoded image as a PNG file. I get numerous unresolved externals in jbig2_image_png.c. You can stub these out, or remove the code entirely since it is mostly used by jbig2dec.c which you won't want.

Anyway, I think you should be able to carry on from here.
Comment 2 Ken Sharp 2010-07-16 08:26:40 UTC
In fact, if you don't use jbig2dec.c (because you supply your own main) then you don't need getopt.c at all and can remove it and getopt1.c from the solution. These are used to process command line arguments, which presumably you won't need.
Comment 3 Thomas Fobear 2010-07-16 14:31:37 UTC
Thank you Ken,

That issue is now resolved, however I am not going to mark this bug as complete. I still have a ways to go untill this can be use as a win32 c++ lib. I now have it compiling, but the linkage is incorrect and I am investigating this now. Note that when I complete this solution I will post a detailed description of this porting experience here, and a working standalone solution for anyone who may have these issues in the future.

The latest error I get is in my DLL that references the library.

error LNK2019: unresolved external symbol "int __cdecl jbig2_image_set_pixel(struct _Jbig2Image *,int,int,int)" (?jbig2_image_set_pixel@@YAHPAU_Jbig2Image@@HHH@Z) referenced in function _jbig2_image_compose_unopt	staticpdf.lib

notice I have already extern "C" the function _jbig2_image_compose_unopt int he file jbig2_image.c

In fact when I follow the path to this code in my DLL which is referencing this it starts at the function "jbig2_data_in" and propogates all the way down to this error. when I extern "C" jbig2_image_set_pixel the same thing happens to that function as jbig2_image_compose_unopt - The compiler dresses it with a leading '_' while I am positive this is not really my problem I realize that, well, I dont really realize what is going on :-X and so it might be worth noting.

one other thing, jbig2_image_compose_unopt was not declared in any header file, so I had added it to jbig2_priv.h where jbig2_image_compose was declared, externing "C" the function definitions in that file (though I realize these are private to the library, hense the _priv)
Comment 4 Ken Sharp 2010-07-17 08:17:33 UTC
(In reply to comment #3)

 
> The latest error I get is in my DLL that references the library.
> 
> error LNK2019: unresolved external symbol "int __cdecl
> jbig2_image_set_pixel(struct _Jbig2Image *,int,int,int)"
> (?jbig2_image_set_pixel@@YAHPAU_Jbig2Image@@HHH@Z) referenced in function
> _jbig2_image_compose_unopt    staticpdf.lib
> 
> notice I have already extern "C" the function _jbig2_image_compose_unopt int he
> file jbig2_image.c

There's a mismatch in function declarations between the prototype in jbig2_image.h:

int jbig2_image_set_pixel(Jbig2Image *image, int x, int y, int value);

and the actual function declaration in jbi2_image.c:

int jbig2_image_set_pixel(Jbig2Image *image, int x, int y, bool value)

Note that one declares 'value' as a bool, the other as an int. If you make these match I think your compilation will work.
Comment 5 Masaki Ushizaka 2010-07-20 09:18:25 UTC
I agree with Ken's proposal.
The patch in comment 4 has been committed as git d26c7e4f39f76fe70cc61d6dc14d05a042a9be48 and svn r11525 (among others).
Making this 'RESOLVED'.