Skip to content

Include headers and FreeType .ccls #977

Open
@513ry

Description

@513ry

Observed behavior

I have actually two problems with this config, so please tell me if I should break this issue into smaller once.

I am trying to reassemble this simple directory structure

├── include
│   ├── my_lib.h
│   └── my_lib
│       └── common.h
├── src
│   └── my_lib.c
└── .ccls

My project use XCB and FreeType, so I included those into my .ccls as well

gcc
-std=c99
-Iinclude
%c -lxcb
%c -lxcb-randr
%c `pkg-config --cflags freetype2`
%c `pkg-config --libs freetype2`

Example with my library code
Peek 2024-11-12 17-45

Expected behavior

I can't get my source directory to see include files.

Second problem is that ccls does seem to recognize the freetype2/ft2build.h header but types and functions defined by it (e.g. FT_Library) are reported as undeclared.

Steps to reproduce

  1. For a minimal reproducible example go
mkdir include src
  1. Create .ccls file in root directory
gxx
-xc
-std=c99
-Iinclude
%c `pkg-config --cflags freetype2`
%c `pkg-config --libs freetype2`
  1. Add CMakeLists.txt to root directory
cmake_minimum_required(VERSION 3.16)
project(test VERSION 0.1.0)

set(CMAKE_C_STANDARD 99)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_STANDARD_REQUIRED YES)
set(CMAKE_C_EXTENSIONS OFF)

find_package(Freetype REQUIRED)

add_executable(${PROJECT_NAME} src/main.c)

target_link_libraries(${PROJECT_NAME}
  PRIVATE
  ${FREETYPE_LIBRARIES})

target_include_directories(${PROJECT_NAME}
  PRIVATE
  include
  ${FREETYPE_INCLUDE_DIRS})
  1. Add the include header
// include/test.h
#ifndef _TEST_H
#define _TEST_H

extern int value = 665;

#endif // _TEST_H
  1. And finally add a source file
// src/main.c
#include "test.h"
#include <freetype2/ft2build.h>
#include FT_FREETYPE_H
#include "stdio.h"
#include <stddef.h>

static FT_Library ft = NULL;

int main(void) {
  printf("value: %i\n", value);
  return 0;
}

System information

  • clang version: 0.20240202-1
  • OS: Arch Linux
  • Editor: Emacs (nvim gives me the same result)
  • Language client (and version): emacs-ccls 20240331.2132

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions