OpenJDK compile problem on Ubuntu 11.10, and the fix
by Sunny Chan
Posted on Friday October 28, 2011 at 10:45am in Java
If you have following the OpenJDK build Readme and try to compile OpenJDK on Ubuntu 11.10, you may see this error:
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `DAUDIO_GetFormats':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x1fd): undefined reference to `snd_pcm_format_mask_malloc'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x20a): undefined reference to `snd_pcm_close'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x225): undefined reference to `snd_pcm_hw_params_malloc'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x236): undefined reference to `snd_pcm_hw_params_get_format_mask'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x246): undefined reference to `snd_pcm_format_mask_free'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x259): undefined reference to `snd_pcm_hw_params_any'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x26a): undefined reference to `snd_pcm_hw_params_get_format_mask'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x277): undefined reference to `snd_pcm_hw_params_get_channels_min'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x288): undefined reference to `snd_pcm_hw_params_get_channels_max'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x2cf): undefined reference to `snd_pcm_format_mask_test'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x45d): undefined reference to `snd_pcm_hw_params_free'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setStartThresholdNoCommit':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x48c): undefined reference to `snd_pcm_sw_params_set_start_threshold'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setStartThreshold':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x4bf): undefined reference to `snd_pcm_sw_params'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setHWParams':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x518): undefined reference to `snd_pcm_hw_params_any'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x531): undefined reference to `snd_pcm_hw_params_set_access'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x544): undefined reference to `snd_pcm_hw_params_set_format'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x557): undefined reference to `snd_pcm_hw_params_set_channels'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x58a): undefined reference to `snd_pcm_hw_params_set_rate_near'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x5dc): undefined reference to `snd_pcm_hw_params_set_buffer_size_near'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x60b): undefined reference to `snd_pcm_hw_params_set_period_time_near'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x61b): undefined reference to `snd_pcm_hw_params'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x647): undefined reference to `snd_pcm_hw_params_set_periods_near'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setSWParams':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x67e): undefined reference to `snd_pcm_sw_params_current'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x6b4): undefined reference to `snd_pcm_sw_params_set_avail_min'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x6c4): undefined reference to `snd_pcm_sw_params'
Don't panic - it looks like the Java's linking sequence for ALSA sound library is wrong. Just use this patch:
--- old/make/javax/sound/jsoundalsa/Makefile 2011-10-28 02:28:00.000000000 -0400
+++ new/make/javax/sound/jsoundalsa/Makefile 2011-10-28 02:28:00.000000000 -0400
@@ -65,7 +65,7 @@
$(MIDIFILES_export) \
$(PORTFILES_export)
-LDFLAGS += -lasound
+EXTRA_LIBS += -lasound
CPPFLAGS += \
-DUSE_DAUDIO=TRUE \
You should be good to go!