diff --git a/avbuild/library.mak b/avbuild/library.mak
index 30757546fdd94477f8cc6b10877335d9854db4fa..4e4b3f196d460457491a0a7f36915f419bffdc05 100644
--- a/avbuild/library.mak
+++ b/avbuild/library.mak
@@ -31,6 +31,8 @@ define RULES
 $(TOOLS):     THISLIB = $(NAME:%=$(LD_LIB))
 $(TESTPROGS): THISLIB = $(SUBDIR)$(LIBNAME)
 
+$(LIBOBJS): CPPFLAGS += -DBUILDING_$(NAME)
+
 $(TESTPROGS) $(TOOLS): %$(EXESUF): %.o
 	$$(LD) $(LDFLAGS) $(LDEXEFLAGS) $$(LD_O) $$(filter %.o,$$^) $$(THISLIB) $(FFEXTRALIBS) $$(EXTRALIBS-$$(*F)) $$(ELIBS)
 
diff --git a/libavcodec/ac3tab.h b/libavcodec/ac3tab.h
index 83edec52d1c2469713684dd60b1b9b848ee551fd..4c0122c39d2e1f73f15b7951df8364c12229021c 100644
--- a/libavcodec/ac3tab.h
+++ b/libavcodec/ac3tab.h
@@ -26,6 +26,7 @@
 
 #include "libavutil/internal.h"
 #include "ac3.h"
+#include "internal.h"
 
 #if CONFIG_HARDCODED_TABLES
 #   define HCONST const
@@ -35,7 +36,7 @@
 
 extern const uint16_t ff_ac3_frame_size_tab[38][3];
 extern const uint8_t  ff_ac3_channels_tab[8];
-extern av_export const uint16_t avpriv_ac3_channel_layout_tab[8];
+extern av_export_avcodec const uint16_t avpriv_ac3_channel_layout_tab[8];
 extern const uint8_t  ff_ac3_enc_channel_map[8][2][6];
 extern const uint8_t  ff_ac3_dec_channel_map[8][2][6];
 extern const uint16_t ff_ac3_sample_rate_tab[3];
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index 787a9c74deb9f5f2de6219adbd881c22225ee459..b2f5cbacf4304ec5b854efc57305b48057d0f3da 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -28,12 +28,12 @@
 #include <stdint.h>
 
 #include "libavutil/float_dsp.h"
-#include "libavutil/internal.h"
 
 #include "avcodec.h"
 #include "dcadsp.h"
 #include "fmtconvert.h"
 #include "get_bits.h"
+#include "internal.h"
 
 #define DCA_PRIM_CHANNELS_MAX  (7)
 #define DCA_ABITS_MAX         (32)      /* Should be 28 */
@@ -288,7 +288,7 @@ typedef struct DCAContext {
     FmtConvertContext fmt_conv;
 } DCAContext;
 
-extern av_export const uint32_t avpriv_dca_sample_rates[16];
+extern av_export_avcodec const uint32_t avpriv_dca_sample_rates[16];
 
 /**
  * Convert bitstream to one representation based on sync marker
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 403fb4a090bcc35f9d9ab643ed53c453cc2f850b..0efe34f6674d5c10992f2350110fd087d6c075bf 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -285,4 +285,14 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
  */
 AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx);
 
+#if defined(_MSC_VER) && CONFIG_SHARED
+#ifdef BUILDING_avcodec
+#    define av_export_avcodec __declspec(dllexport)
+#else
+#    define av_export_avcodec __declspec(dllimport)
+#endif
+#else
+#    define av_export_avcodec
+#endif
+
 #endif /* AVCODEC_INTERNAL_H */
diff --git a/libavcodec/jpegtables.h b/libavcodec/jpegtables.h
index 1a909bef7abded00178cbf595a7f779d5402b467..44c2acabc470339440b3f627cd2bb24fe4ea0daf 100644
--- a/libavcodec/jpegtables.h
+++ b/libavcodec/jpegtables.h
@@ -23,18 +23,18 @@
 
 #include <stdint.h>
 
-#include "libavutil/internal.h"
+#include "internal.h"
 
-extern av_export const uint8_t avpriv_mjpeg_bits_dc_luminance[];
-extern av_export const uint8_t avpriv_mjpeg_val_dc[];
+extern av_export_avcodec const uint8_t avpriv_mjpeg_bits_dc_luminance[];
+extern av_export_avcodec const uint8_t avpriv_mjpeg_val_dc[];
 
-extern av_export const uint8_t avpriv_mjpeg_bits_dc_chrominance[];
+extern av_export_avcodec const uint8_t avpriv_mjpeg_bits_dc_chrominance[];
 
-extern av_export const uint8_t avpriv_mjpeg_bits_ac_luminance[];
-extern av_export const uint8_t avpriv_mjpeg_val_ac_luminance[];
+extern av_export_avcodec const uint8_t avpriv_mjpeg_bits_ac_luminance[];
+extern av_export_avcodec const uint8_t avpriv_mjpeg_val_ac_luminance[];
 
-extern av_export const uint8_t avpriv_mjpeg_bits_ac_chrominance[];
-extern av_export const uint8_t avpriv_mjpeg_val_ac_chrominance[];
+extern av_export_avcodec const uint8_t avpriv_mjpeg_bits_ac_chrominance[];
+extern av_export_avcodec const uint8_t avpriv_mjpeg_val_ac_chrominance[];
 
 void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
                                   const uint8_t *bits_table,
diff --git a/libavcodec/mpeg4audio.h b/libavcodec/mpeg4audio.h
index 01f30c6ca7097be0a1da1ba5aaf31572ce91ec83..0a0905888aec8ddeeca4d66d20ab046980e1056f 100644
--- a/libavcodec/mpeg4audio.h
+++ b/libavcodec/mpeg4audio.h
@@ -27,6 +27,7 @@
 #include "libavutil/attributes.h"
 
 #include "get_bits.h"
+#include "internal.h"
 #include "put_bits.h"
 
 typedef struct MPEG4AudioConfig {
@@ -44,7 +45,7 @@ typedef struct MPEG4AudioConfig {
     int frame_length_short;
 } MPEG4AudioConfig;
 
-extern av_export const int avpriv_mpeg4audio_sample_rates[16];
+extern av_export_avcodec const int avpriv_mpeg4audio_sample_rates[16];
 extern const uint8_t ff_mpeg4audio_channels[8];
 
 /**
diff --git a/libavcodec/mpegaudiodata.h b/libavcodec/mpegaudiodata.h
index 2b8ff6587fcc9ae5041ee4200f9fd1cb1defa4ac..1609f48e433c82ef131a5b8eabd1d7ccfa626d1a 100644
--- a/libavcodec/mpegaudiodata.h
+++ b/libavcodec/mpegaudiodata.h
@@ -29,13 +29,13 @@
 
 #include <stdint.h>
 
-#include "libavutil/internal.h"
+#include "internal.h"
 
 #define MODE_EXT_MS_STEREO 2
 #define MODE_EXT_I_STEREO  1
 
-extern av_export const uint16_t avpriv_mpa_bitrate_tab[2][3][15];
-extern av_export const uint16_t avpriv_mpa_freq_tab[3];
+extern av_export_avcodec const uint16_t avpriv_mpa_bitrate_tab[2][3][15];
+extern av_export_avcodec const uint16_t avpriv_mpa_freq_tab[3];
 extern const int ff_mpa_sblimit_table[5];
 extern const int ff_mpa_quant_steps[17];
 extern const int ff_mpa_quant_bits[17];
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 8a0076f9850587d838ff29fa52b62e484ca2a077..7071d2a587b18b5d0ee9bbb3bd6eaeffcf941027 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -57,12 +57,6 @@
 #endif
 #endif
 
-#if defined(_MSC_VER) && CONFIG_SHARED
-#    define av_export __declspec(dllimport)
-#else
-#    define av_export
-#endif
-
 #if HAVE_PRAGMA_DEPRECATED
 #    if defined(__ICL)
 #        define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))