jiixyj / libebur128

A library implementing the EBU R128 loudness standard.
MIT License
402 stars 76 forks source link

Trying to build Win32 DLL #40

Closed tweibert closed 8 years ago

tweibert commented 9 years ago

Hi,

just found this library today, and I have been trying to build a shared library for Win32 to use it in a Delphi project (I will port the header files manually).

I have VS C++ 2008 Express installed. Is VC the preferred build environment under Windows? Or should I go for MinGW? I must admit that I'm not an expert for either toolchain.

CMake generated several VS project files, but I can't get them to compile. First problem was, VC did not find sys/queue.h, so I had to add the "queue" directory manually to the includes in the project config.

Now the compiler is complaining:

1>.\ebur128.c(413) : fatal error C1021: invalid preprocessor command 'warning'

Which points to the following line:

#warning "manual FTZ is being used, please enable SSE2 (-msse2 -mfpmath=sse)"

So it seems that SSE2 was not turned on. After a Google search, I found that I have to set "Enable Enhanced Instruction Set" to "SSE2", but I still get the same error. Looks like the SSE2 defines are different on Windows?

Has anyone has any luck compiling a Windows DLL from this? Are there possibly any binaries available somewhere? Or can you give me some hints about the above problems?

Thanks, Torben

jiixyj commented 9 years ago

Does it compile if you delete the "warning" line? Also, for a shared library under Windows, all symbols must be exported in the header file with a special syntax: https://msdn.microsoft.com/en-us/library/a90k134d.aspx. I'll try to fix those issues once I get access to VS next week.

tweibert commented 9 years ago

Thanks for the feedback. I commented out the warning line, and also added __declspec(dllexport) (through a LIBRARY_API define) to all functions in ebur128.h. Now I managed to build ebur128.dll. Also checked it with dllexp.exe, all function exports seem to be there. So far so good.

I'm not a C expert, so I don't feel like providing a proper, clean pull request for this.

And also, this is a build without Speex (and maximum peak) though. Can you provide build instructions for that?

Thank you so much for your efforts. This is the library I have been looking for for years.

I will contribute the Delphi headers once I have them ready.

tweibert commented 8 years ago

Any progress here? Would really love to use this lib in my Delphi project.

jiixyj commented 8 years ago

I have fixed some of those issues locally. I'll commit/push them ASAP. I haven't tried to build speexdsp with Visual Studio yet, but it should be possible with their VS solutions (https://github.com/xiph/speexdsp/tree/master/win32/VS2008).

tweibert commented 8 years ago

Sounds great, thanks. If you were able to produce a DLL during your tests, could you post it please?

ghost commented 8 years ago

Hello,

I sent in a pull request earlier today (#52) that should help. The commit should resolve the SSE2 compile issues, and ensures a MSVC-compiled shared library exports symbols (via a def file).

With that applied, you should be able to compile on Windows - just be sure to set the ENABLE_INTERNAL_QUEUE_H to ON in the cmake options.

rdp commented 8 years ago

As a side note, using cmake cross compile I get:

-- queue.h: no using system copy of queue.h

but then

/Users/packrd/dev/ruby/2ffmpeg-windows-bh/sandbox/win32/lib_ebur128_git/ebur128/ebur128.c:12:23: fatal error: sys/queue.h: No such file or directory

perhaps it could check for system copy existence as well? (fix is to use the ENABLE... flag SZ-MSFT mentioned). Thanks!

ghost commented 8 years ago

There appears to be a bug in the CMake script where, even when you don't have a valid system queue.h, configuration still succeeds. I've updated my pull request with a fix. In the main CMakeLists file, just change:

if(NOT SUMMARY_HAS_QUEUE AND NOT ENABLE_INTERNAL_QUEUE_H) to if(NOT ${SUMMARY_HAS_QUEUE} AND NOT ${ENABLE_INTERNAL_QUEUE_H})

This should cause the configuration step to fail, and prompt the user to use the internal queue. I'm not sure if this will resolve the issue when cross compiling, though.

dts350z commented 8 years ago

I did the above RE: queue.h. Now I have (on visual studio 2015):

C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(27): error C2061: syntax error: identifier 'SLIST_ENTRY' 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(28): error C2059: syntax error: '}' 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(52): error C2079: 'block_list' uses undefined struct 'ebur128_double_queue' 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(54): error C2079: 'short_term_block_list' uses undefined struct 'ebur128_double_queue' 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(293): warning C4013: 'SLIST_INIT' undefined; assuming extern returning int 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(350): warning C4013: 'SLIST_EMPTY' undefined; assuming extern returning int 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(351): warning C4013: 'SLIST_FIRST' undefined; assuming extern returning int 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(351): warning C4047: '=': 'ebur128_dq_entry ' differs in levels of indirection from 'int' 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(352): warning C4013: 'SLIST_REMOVE_HEAD' undefined; assuming extern returning int 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(352): error C2065: 'entries': undeclared identifier 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(356): warning C4047: '=': 'ebur128_dq_entry ' differs in levels of indirection from 'int' 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(357): error C2065: 'entries': undeclared identifier 2>C:\Users\gnewell\Downloads\libebur128-master (1)\libebur128-master\ebur128\ebur128.c(413): fatal error C1021: invalid preprocessor command 'warning'

dts350z commented 8 years ago

Progress.

I needed to:

include ".\queue\sys\queue.h"

and comment out:

//#warning "manual FTZ is being used, please enable SSE2 (-msse2 -mfpmath=sse)"

ghost commented 8 years ago

Is that issue using the patch I submitted for Win32 compilation, or the main branch? The patch should instruct VS to build with SSE2 enabled and set flags to prevent SSE2 warnings.

With the patch applied, it is building without error on my system (VS2015).

dts350z commented 8 years ago

Pretty sure I just downloaded the main branch.

It wasn't clear to me what the other branch was.

ghost commented 8 years ago

The issues should be fixed in pull request #52 - it should be the same as the main branch, but with a few CMake changes applied to ensure smooth compilation on windows (as well as a def file to ensure symbol exports).

jiixyj commented 8 years ago

I've merged PR #52 and added some new library symbols to the ebur128.def. Hopefully building/using the library should "just work" now in VS.

Boscop commented 8 years ago

I'm trying to build it but I get an error:

D:\3rdparty\libebur128\build>cmake ..
-- Building for: Visual Studio 14 2015
-- The C compiler identification is MSVC 19.0.23506.0
-- Check for working C compiler using: Visual Studio 14 2015
-- Check for working C compiler using: Visual Studio 14 2015 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Status          found / disabled --
-- queue.h:        no      using system copy of queue.h
-- build static library and shared library!
CMake Error at CMakeLists.txt:33 (message):
  queue.h not found, please set ENABLE_INTERNAL_QUEUE_H to ON

-- Configuring incomplete, errors occurred!
See also "D:/3rdparty/libebur128/build/CMakeFiles/CMakeOutput.log".
jiixyj commented 8 years ago

cmake .. -DENABLE_INTERNAL_QUEUE_H=ON should do the trick.

Boscop commented 8 years ago

Builds both static and dynamic now. Thanks!

jiixyj commented 8 years ago

Great! Closing.