diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 0fd4c71..3dcf42c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -594,7 +594,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		if (sym.source_reference != null) {
 			sym.source_reference.file.used = true;
 		}
-		if (sym.external_package || (!decl_space.is_header && CodeContext.get ().use_header && !sym.is_internal_symbol ())) {
+		if (sym.external_package && sym.external || (!decl_space.is_header && CodeContext.get ().use_header && !sym.is_internal_symbol ())) {
 			// add appropriate include file
 			foreach (string header_filename in get_ccode_header_filenames (sym).split (",")) {
 				decl_space.add_include (header_filename, !sym.external_package ||
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index d949c61..fa6fe4b 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -59,6 +59,15 @@ public class Vala.Delegate : TypeSymbol {
 		}
 	}
 
+	public override bool external {
+		get {
+			return !get_attribute_bool ("CCode", "always_declare") && base.external;
+		}
+		set {
+			base.external = value;
+		}
+	}
+
 	public DataType? sender_type { get; set; }
 
 	private List<TypeParameter> type_parameters = new ArrayList<TypeParameter> ();
diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala
index cc92116..1e75cfa 100644
--- a/vala/valasymbol.vala
+++ b/vala/valasymbol.vala
@@ -188,7 +188,7 @@ public abstract class Vala.Symbol : CodeNode {
 	 * Specifies whether the implementation is external, for example in
 	 * a separate C source file or in an external library.
 	 */
-	public bool external { get; set; }
+	public virtual bool external { get; set; }
 
 	/**
 	 * Specifies whether the implementation is in an external library.
diff --git a/vapi/posix.vapi b/vapi/posix.vapi
index 9578263..caf5427 100644
--- a/vapi/posix.vapi
+++ b/vapi/posix.vapi
@@ -2490,7 +2490,7 @@ namespace Posix {
 		}
 	}
 
-	[CCode (has_target = false)]
+	[CCode (has_target = false, always_declare = true)]
 	public delegate int GlobErrorFunction (string filename, int errcode);
 
 	[CCode (cheader_filename = "glob.h")]
