Sample Header Ad - 728x90

Kate Editor LSP Client: Any way to specify an "entry file" for compilation?

0 votes
1 answer
648 views
Goal: If I have two c files, A and B, and I don't plan to compile B into an object file, but rather include it directly in A, can clangd (or any other LSP service that works with Kate) show me only the errors in B that arise from compiling A directly? In other words, A is the "entry file" for compilation errors in B. Please bare with the me on the snubbing of standard include practices. Simplest example: Let's say this is main.c: #include #include "test.c" int main() { test(); return 0; } and test.c is: void test() { printf("Hello world!\n"); } If I were to compile test.c into an object file, I would get the following errors: > clang -c test.c -o test test.c:2:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration] printf("Hello world!\n"); ^ test.c:2:5: note: include the header or explicitly provide a declaration for 'printf' Kate's LSP Server will of course pick up on this and highlight "printf" in test.c for fixing. Now, let's say I have no plan to compile test.c separately. I only want to run: clang main.c Which will include test.c AFTER stdio is included in main.c, and thus compile without errors. Therefore the printf warning the LSP server shows me - while good for demonstrating test.c's compile-ability in isolation - will be irrelevant to how I ultimately compile the program. In this scenario, can I tell the LSP server to ONLY compile main.c (treat main.c as the "entry point" of compilation), and then have kate only highlight the errors in test.c that would arise from compiling main.c? In the concrete example, this would lead to NO errors being highlighted in test.c. I might also be snubbing the definition of "entry point", since it usually refers to runtime entry point, not certain compilation choices, but if there's a name for what I'm asking for, I'm not sure what it is.
Asked by Eagle Orion (1 rep)
Sep 24, 2022, 07:45 PM
Last activity: Feb 24, 2023, 01:29 PM