             var libs = [String]()
             
             for dep in dependencies {
+                let firstOccurrence = loadingContext.pkgConfigStack.firstIndex(of: dep)
+
+                if let index = firstOccurrence {
+                    diagnostics.emit(warning: "circular dependency detected while parsing \(loadingContext.pkgConfigStack[0]): \(loadingContext.pkgConfigStack[index..<loadingContext.pkgConfigStack.count].joined(separator: " -> ")) -> \(dep)")
+                    continue
+                }
+
                 // FIXME: This is wasteful, we should be caching the PkgConfig result.
                 let pkg = try PkgConfig(
-                    name: dep, 
+                    name: dep,
                     additionalSearchPaths: additionalSearchPaths,
                     diagnostics: diagnostics,
                     fileSystem: fileSystem,
-                    brewPrefix: brewPrefix
+                    brewPrefix: brewPrefix,
+                    loadingContext: loadingContext
                 )
 
                 cFlags += pkg.cFlags

        additionalSearchPaths: [AbsolutePath] = [],
        diagnostics: DiagnosticsEngine,
        fileSystem: FileSystem = localFileSystem,
        brewPrefix: AbsolutePath?
    ) throws {

        if let path = try? AbsolutePath(validating: name) {
            guard fileSystem.isFile(path) else { throw PkgConfigError.couldNotFindConfigFile(name: name) }

    }
}

/// Informations to track circular dependencies and other PkgConfig issues
public class LoadingContext {
    public init() {
        pkgConfigStack = [String]()
    }

    public var pkgConfigStack: [String]
}

/// Information on an individual `pkg-config` supported package.
public struct PkgConfig {
    /// The name of the package.
