Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: [C++] Unable to compile Flac code. (Read 7579 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[C++] Unable to compile Flac code.

Hi, i'm trying to compile the encode example of libflac for C++, but i can't. I recive always a lot of "undefined reference to" error (like "undefined reference to `FLAC::Encoder::Stream::get_state() const"). I use DevC++ 5.6.1 with Mingw 4.8.1 and windows 7 64bit. I add to the project the libFlac++.lib but it doesn't work. I don't know what to do. I apologise for my english.

link to encode example: http://flac.cvs.sourceforge.net/viewvc/fla...amp;view=markup

I download this library: flac-1.2.1-devel-win.zip at http://sourceforge.net/projects/flac/files...flac-1.2.1-win/ i hope it's good for me.

[C++] Unable to compile Flac code.

Reply #1
From export.h:

Code: [Select]
If you are compiling with MSVC and will link to the static library
(libFLAC++.lib) you should define FLAC__NO_DLL in your project to
make sure the symbols are exported properly.


Maybe that's your case.

[C++] Unable to compile Flac code.

Reply #2
I add "#define FLAC__NO_DLL" to my project but it doesn't work. Also tried with libFlac++_static.lib

[C++] Unable to compile Flac code.

Reply #3
Another reason is different name mangling. Are you sure that MinGW and MSVC are compatible in this way?

--
added: http://www.mingw.org/wiki/MixingCompilers

[C++] Unable to compile Flac code.

Reply #4
I would use a more recent version than FLAC 1.2.1 to start with. Quite a few compile time changes were included in 1.3.0 (and even more if you do a checkout of what eventually will become 1.3.1 but that's not released yet so act with caution) as 1.2.1 is fairly old and so created for relatively old build environments. Windows 7 didn't exist when 1.2.1 came out and even Windows Vista was brand new. Version 1.2.1 wasn't made for "fancy" things such as successors to Windows XP, 64 bit or Unicode on Windows.

Have a look on the FLAC download page for 1.3.0
Every night with my star friends / We eat caviar and drink champagne
Sniffing in the VIP area / We talk about Frank Sinatra
Do you know Frank Sinatra? / He's dead

[C++] Unable to compile Flac code.

Reply #5
To be onest i'm not sure about anything. I try to compile with microsoft visual studio express 2013 and i get only 9 error this time.I added the FLAC__NO_DLL and libFlac++.lib. In few word i get: Error lnk2001 for:
Code: [Select]
"public: virtual bool __thiscall FLAC::Encoder::Stream::process(int const * const * const,unsigned int)" (?process@Stream@Encoder@FLAC@@UAE_NQBQBHI@Z)
"public: virtual bool __thiscall FLAC::Encoder::Stream::process_interleaved(int const * const,unsigned int)" (?process_interleaved@Stream@Encoder@FLAC@@UAE_NQBHI@Z)
"public: virtual void __thiscall FLAC::Encoder::Stream::get_verify_decoder_error_stats(unsigned __int64 *,unsigned int *,unsigned int *,unsigned int *,int *,int *)" (?get_verify_decoder_error_stats@Stream@Encoder@FLAC@@UAEXPA_KPAI11PAH2@Z)
__imp__FLAC__StreamEncoderInitStatusString

And error lnk2019 for:
Code: [Select]
 "__declspec(dllimport) public: virtual bool __thiscall FLAC::Encoder::Stream::process_interleaved(int const * const,unsigned int)" (__imp_?process_interleaved@Stream@Encoder@FLAC@@UAE_NQBHI@Z)
__imp__FLAC__metadata_object_delete
__imp__FLAC__metadata_object_new
__imp__FLAC__metadata_object_vorbiscomment_append_comment
__imp__FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair

While with Dev C++ i get 77 error. Later i try the file of version 1.3.0 and i get the same error. Both visual studio and dev c++. Another thing i don't understand is that, there is no file .lib inside the library downloaded from list linked in the official site (Here i mean http://downloads.xiph.org/releases/flac/ ) But i have download them from another place, on sourceforge page of libflac.Of course for windows. So am i wrong something?

[C++] Unable to compile Flac code.

Reply #6
Could you please be a little more specific? Which code are you compiling exactly? The example_cpp_encode_file project in MSVC? Could it be there are errors earlier in the compile proces, when compiling libFLAC? Do you have a platform SDK? Did you install the ogg dependency?
Music: sounds arranged such that they construct feelings.

[C++] Unable to compile Flac code.

Reply #7
AFAIK FLAC 1.2.1 was built with Visual Studio 6.

In libFLAC++.lib from flac-1.2.1-devel-win.zip I can see the following:
Code: [Select]
?process_interleaved@Stream@Encoder@FLAC@@UAE_NQB_HI@Z

And as you can see, MSVS2013 looks for:
Code: [Select]
?process_interleaved@Stream@Encoder@FLAC@@UAE_NQBHI@Z

`UAE_NQB_HI' vs. `UAE_NQBHI'

It seems that MSVS 2013 (aka Visual Studio 12) is not fully compatible with Visual Studio 6. So just take FLAC 1.3.0 sources and compile all necessary lib/dlls yourself.

[C++] Unable to compile Flac code.

Reply #8
I'm compiling example_cpp_encode_file project with devC++ and MSVC. Both without success. I'm sure there is no error before linking. The code is correct. So i don't think there are problem until linking. For the platform SDK, wikipedia say that is included in Visual Studio 2013. About the ogg dependency i don't understand if i need to add something to the project becouse the code don't include anything about ogg.h. I try to include ogg_static.lib to the project but doesn't work.

About the compillig lib/dll myself, i dont' know how do it. I try to generate file .a  from every file .h of the library, but doesn't work. I suppose becouse in these file there are only the declaration of function, but not the complete function (that i can't find in the source). And now i finish the ideas

[C++] Unable to compile Flac code.

Reply #9
I'm compiling example_cpp_encode_file project with devC++ and MSVC.

About the compillig lib/dll myself, i dont' know how do it. I try to generate file .a  from every file .h of the library, but doesn't work. I suppose becouse in these file there are only the declaration of function, but not the complete function (that i can't find in the source).

The sources are in flac-1.3.0.tar.xz file from http://downloads.xiph.org/releases/flac/
Also you should use example_cpp_encode_file version from flac-1.3.0.tar.xz: it is guaranteed to be compatible with that library.

[C++] Unable to compile Flac code.

Reply #10
of course, i didn't think about use new version of the example.
It seems that MSVS 2013 (aka Visual Studio 12) is not fully compatible with Visual Studio 6. So just take FLAC 1.3.0 sources and compile all necessary lib/dlls yourself.
I don't know how proceed now. I try to compile myself all necessary file .lib/.dll but i'm not sure i do it the right way. Can you explain how make from myself the file .lib and .dll? I mean after create a lib project, what do i add to the project? Only the file .h inside folder "include"? (i mean encode.h, decode.h,metadata.h, ecc.) Now with DevC++ , i can only get a file .a that has inside only "!<arch>". (i use devC++ for simplicity)

[C++] Unable to compile Flac code.

Reply #11
Never used Dev-C++ so don't know what to do with it.

(But of course you need all *.c files inside src/libFLAC to build libFLAC.a and all *.cpp files inside src/libFLAC++ to build libFLAC++.a)

[C++] Unable to compile Flac code.

Reply #12
I mean if is it right to put inside the project all the file .h inside the folder include/Flac++ without anything else like a main?(or put inside every file .h/.cpp i find in the library). Becouse in this way i get a file.a of 8 bytes from devC++. With Code::Blocks 13.12 i get a good .a file, but linking to project don't make me compile it. Don't work.

Do you know where precisely are the function and every else about flac defined? In which file? Becouse i think that inside the header included in the example, there are a lot of declaration without definition. This confuse me