xinxinlx / openjpeg

Automatically exported from code.google.com/p/openjpeg
Other
0 stars 0 forks source link

undefined reference to `opj_version' #200

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm trying to compile a simple example program that uses openjpeg 2.0.0.

The example program is:
extern int opj_version();
int main(void){ opj_version(); }

I'm compiling it with: i686-w64-mingw32-gcc ./test-openjpeg.c -lopenjp2

I get the error:
/tmp/cci01N0F.o:test-openjpeg.c:(.text+0xc): undefined reference to 
`opj_version'
collect2: error: ld returned 1 exit status

When running: i686-w64-mingw32-nm 
'/home/kyle/software/ffmpeg/pkgs/openjpeg/openjpeg-2.0.0-win32/lib/libopenjp2.a'
 | grep opj_version

I get the output:
00000228 T _opj_version@0

Does anyone know why I might be having this issue? I can provide any further 
details.

Original issue reported on code.google.com by zera...@gmail.com on 9 Dec 2012 at 4:57

GoogleCodeExporter commented 9 years ago
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <openjpeg.h>

int main(void)
{
    printf("OPJ2 version is %s\n",opj_version());

    return 0;
}

This simple program version2.c I have compiled with:

gcc version2.c -o version2 -I/usr/local/opj2/include/openjpeg-2.0/openjpeg.h 
-L/usr/local/opj2/lib -lopenjp2

And called:

./version2

OPJ2 version is 2.0.0

winfried

Original comment by szukw...@arcor.de on 10 Dec 2012 at 6:13

GoogleCodeExporter commented 9 years ago
I tried to compile your example program and got a failed result.

Here is my output:

$ cat ./version2.c 
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <openjpeg.h>

int main(void)
{
    printf("OPJ2 version is %s\n",opj_version());

    return 0;
}

$ i686-w64-mingw32-gcc version2.c -o version2 
"-I/home/kyle/software/ffmpeg/pkgs/openjpeg/openjpeg-2.0.0-win32/include/openjpe
g-2.0" "-L/home/kyle/software/ffmpeg/pkgs/openjpeg/openjpeg-2.0.0-win32/lib" 
-lopenjp2
/tmp/cc0A0ds4.o:version2.c:(.text+0xf): undefined reference to 
`_imp__opj_version@0'
collect2: error: ld returned 1 exit status

So now I get an undefined reference to `_imp__opj_version@0'

Original comment by zera...@gmail.com on 10 Dec 2012 at 4:30

GoogleCodeExporter commented 9 years ago
The 'imp' prefix usually means: I expect a dynamic library.
Is there a 'bin/openjp2.dll' on your system?

winfried

Original comment by szukw...@arcor.de on 10 Dec 2012 at 8:20

GoogleCodeExporter commented 9 years ago
I compile the lib statically, and there are no .dll files present.

Original comment by zera...@gmail.com on 10 Dec 2012 at 9:39

GoogleCodeExporter commented 9 years ago
I compile openjpeg with:
-DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_SYSTEM_NAME=Windows-GNU 
-DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ 
-DCMAKE_INSTALL_PREFIX=/home/kyle/software/ffmpeg/pkgs/openjpeg/openjpeg-2.0.0-w
in32 -DBUILD_SHARED_LIBS:bool=off 
-DZLIB_INCLUDE_DIR=/home/kyle/software/ffmpeg/pkgs/zlib/zlib-1.2.7/include 
-DZLIB_LIBRARY=/home/kyle/software/ffmpeg/pkgs/zlib/zlib-1.2.7/lib 
-DBUILD_THIRDPARTY=1 -DCMAKE_C_FLAGS=-DOPJ_STATIC ../source/openjpeg-2.0.0

openjpeg compiles fine, and I don't run into any errors until I try to use the 
lib.

Original comment by zera...@gmail.com on 11 Dec 2012 at 3:43

GoogleCodeExporter commented 9 years ago
I fixed this issue by manually editing the code and commenting out all 
"__declspec(dllexport)" and "__declspec(dllimport)".

I then compiled with:
-DOPJ_STATIC -DDLL_EXPORT=

It seems to be working now.

Original comment by zera...@gmail.com on 12 Dec 2012 at 2:20

GoogleCodeExporter commented 9 years ago
Looks like I spoke too soon.

When trying to compile the original code I had issues with:
extern int opj_version();
int main(void){ opj_version(); }

I get the error again.

The code that compiled was:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <openjpeg.h>

int main(void)
{
    printf("OPJ2 version is %s\n",opj_version());

    return 0;
}

I'm not sure why that works and the other doesn't though.

I still think this issue is related to a dll/dynamic lib issue but I can't 
confirm that.

If any information is needed let me know, I would like to see this issue 
resolved.

Original comment by zera...@gmail.com on 12 Dec 2012 at 4:09

GoogleCodeExporter commented 9 years ago
The prototype of opj_version is :
OPJ_API const char * OPJ_CALLCONV opj_version(void);

It is not int opj_version();

So your test program is wrong.

You should not try to redefine the openjpeg headers content yourself, just 
stick with "#include <openjpeg.h>" and you should be safe.

Original comment by julien.m...@gmail.com on 17 Dec 2012 at 1:39

GoogleCodeExporter commented 9 years ago
Closing as invalid. Thanks Julien for catching this !

Original comment by mathieu.malaterre on 17 Dec 2012 at 1:41

GoogleCodeExporter commented 9 years ago
Also, the name of the functions in the public API can be mangled.
Another reason to say that defining the openjpeg headers content yourself is 
wrong.

Original comment by julien.m...@c-s.fr on 17 Dec 2012 at 1:42