Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to `opj_version' #200

Closed
gcode-importer opened this issue Dec 9, 2012 · 10 comments
Closed

undefined reference to `opj_version' #200

gcode-importer opened this issue Dec 9, 2012 · 10 comments

Comments

@gcode-importer
Copy link

Originally reported on Google Code with ID 200

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.

Reported by zeranoe on 2012-12-09 16:57:30

@gcode-importer
Copy link
Author

#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

Reported by szukw000 on 2012-12-10 06:13:02

@gcode-importer
Copy link
Author

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/openjpeg-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'

Reported by zeranoe on 2012-12-10 16:30:33

@gcode-importer
Copy link
Author

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

winfried

Reported by szukw000 on 2012-12-10 20:20:54

@gcode-importer
Copy link
Author

I compile the lib statically, and there are no .dll files present.

Reported by zeranoe on 2012-12-10 21:39:04

@gcode-importer
Copy link
Author

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-win32
-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.

Reported by zeranoe on 2012-12-11 15:43:09

@gcode-importer
Copy link
Author

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.

Reported by zeranoe on 2012-12-12 02:20:19

@gcode-importer
Copy link
Author

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.

Reported by zeranoe on 2012-12-12 04:09:16

@gcode-importer
Copy link
Author

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.





Reported by julienmalik on 2012-12-17 13:39:00

@gcode-importer
Copy link
Author

Closing as invalid. Thanks Julien for catching this !

Reported by malaterre on 2012-12-17 13:41:05

  • Status changed: Invalid

@gcode-importer
Copy link
Author

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.

Reported by julienmalik on 2012-12-17 13:42:48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant