Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include headers and FreeType .ccls #977

Open
513ry opened this issue Nov 13, 2024 · 2 comments
Open

Include headers and FreeType .ccls #977

513ry opened this issue Nov 13, 2024 · 2 comments

Comments

@513ry
Copy link

513ry commented Nov 13, 2024

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
@FederAndInk
Copy link
Contributor

FederAndInk commented Nov 13, 2024

if you are using cmake, try using compile_commands.json instead of .ccls, e.g. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

either way, I don't think ccls will interpret commands in a .ccls file, your issue is probably that you're trying to use `pkg-config ...` where you should only put flags directly

take a look at this page for more details: https://github.com/MaskRay/ccls/wiki/Project-Setup

@513ry
Copy link
Author

513ry commented Nov 13, 2024

@FederAndInk I have tried to put flags returned by pkg_config directly, with the same result. I used pkg_config here for short.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants