I'm using Visual Studio Code to manage a C project that contains a number of libraries and fully-linked executables. When the executables need to depend on headers from a library, rather that point at the library's source files directly, they point at a build directory containing the headers. That is, for a source layout like:
project/lib/src/lib.h
project/exe/src/exe.c
Rather than the build for project/exe including -I project/lib/src, it does -I project/lib/build, which will have a copy of lib.h in it from the last time the library was built. This is done for miscellaneous reasons that don't matter here, and mostly works fine, except when I use vscode's "Go to Definition" feature (F12, Ctrl+Click, etc.).
Because vscode is using the compiler's include path to know where to find headers, if I go to the definition of anything in lib.h, vscode will open project/lib/build/lib.h instead of project/lib/src/lib.h. Is there a way, either built-in or via a plugin, to hook vscode's belief that it should open project/lib/build/lib.h and change it to project/lib/src/lib.h? I'm even willing to write a plugin, but I couldn't find a way to either modify the language server's result to change the path, or intercept vscode attempting to open a particular path and change it on-demand.
Related
I have successfully compiled (azure_iot_sdk_c) on Linux and successfully run this demo (iothub_ll_c2d_sample). Now, I want to extract the source code related to this demo to facilitate the migration to the embedded Linux platform. What should I do? The source code provided by Microsoft contains a lot of code unrelated to the Linux platform in order to be compatible with more platforms.
I tried to take out the source code in the sdk, delete the code of other platforms, and judge whether the platform is related by the file name, but it could not be compiled. I want to know what files are required for this demo (iothub_ll_c2d_sample) to run normally. I want to take them out and compile them separately, so that they can be ported to the embedded Linux platform.
You can extract the code sample file and compile it independently by importing the required header files for the code in iothub_ll_c2d_sample.c
Even though the code lists only six external reference files, some of the header files have internal dependencies. By back tracing, I found eighteen header files that are referenced by them. You would have to provide a local reference to all these files to make the code compile successfully. Please find the below image referring all the header files the program needs to compile.
You can get the header files from the below URLs
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/map.h
https://github.com/Azure/azure-iot-arduino-utility/blob/master/src/azure_c_shared_utility/azure_macro_utils/macro_utils.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_device_client_ll.h
https://github.com/Azure/azure-iot-arduino-utility/blob/master/src/azure_c_shared_utility/azure_macro_utils/macro_utils_generated.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_transport_ll.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_client_core_ll.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_client_core_common.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_message.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/strings.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/const_defines.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/strings_types.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothubtransportmqtt.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/shared_util_options.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/crt_abstractions.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/threadapi.h
https://github.com/Azure/umock-c/blob/master/inc/umock_c/umock_c_prod.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_client_options.h
Note that since I have the files under the same directory, I will no longer need to provide a relative path while referencing the header files in the program. I can directly access them as below
The same goes with the header files. I can directly refer the dependent header files without providing any relative path. Please find the below image of the iothub.h header file which refernces umock_c_prod.h file and notice there is no relative path.
If you decide to place the header files under a different directory, make sure to provide a relative path for the code to compile.
I want to run a C project on Compiler Explorer (godbolt.org) which includes some external header files. What is the procedure to include these third-party header files on there?
Screenshot of the project
Suppose I want to run this code which includes snipmath.h file. Also, snipmath.h header includes other lib files. How can I include all of them in godbolt? like we usually do in a offline compiler.
Remarkably, only 1 week before you posted the question this feature was added to compiler explorer. As of Nov 2021 it is reported to still have some rough edges, and not every combination of controls work - but starting from the simple template Matt delivered and following his instructions work for me:
go to compiler explorer
click "Add..." at the very top left and choose "Tree (IDE mode)".
Move the files you have open into "Included files" with the plus (you will have to give them names)
(For C++) tick "CMake" and then create a CMakeLists.txt with appropriate info it in
Ensure it says -DCMAKE_BUILD_TYPE=Debug in the box under
In the box under that choose the name of your target, e.g. "test"
You can then "Add new..." and make a compiler that will run CMake
Note this does not include uploading the headers, but rather pasting them in new CE editors. Also, judging by your screenshot - when you write 'other lib files' I assume you mean other headers. Lib files aren't supported.
If your project was a CMake one, you might have been able to upload it directly (someone did).
You can use Compiler Explorer with Cmake and have multiple header and source files. You could even have some other files to read from (like *.ini). Try it here reading *.ini in Compiler Explorer
Note: the examples are with C++, but it must be straightforward to do it with C.
When using the C/C++ extension for Visual Studio Code with WSL, it will never refer to /usr/include/ unless you create a project file any time, as you have to allow it to create a local config file called c_cpp_properties.json. This means you simply cannot run standalone C files unless you create a workspace around it.
Is there some way to automate this, even a little? It's very annoying having to redefine my standard includes every time I reopen the program.
Ideally I would like to set this up such that I can just work with my C files standalone rather than as a project as I am frequently using university assets and it's very annoying to have to create a project to work with any demo they give me. I have looked everywhere but just can't find any kind of global setting where I can tell the extension to refer to /usr/include/ - with or without a local config file for the project.
Thanks
I have to create one-file (.exe) program.
In this program user can choose directory from his computer.
I create program in order of http://www.tarnyko.net/en/?q=node/31 and it run well.
But when I invoke FileChoser (click on button) I got this error
GLib-GIO-ERROR No GSettings schemas are installed on the system
Response of Tarnyko to this issue is in coment on webpage - this is known "bug" with static compiling.
How can I work around this?
On the one hand I have to have one-file.exe.
On the other hand I realy do not want create "sophisticated" FileChooser on my own... is there any option to deal with this?
My ideas:
1 - Call native File chooser of OS (windows)
2 - Create file chooser on my own - if it is not "much hard" in gtk
I do not know how to do either of this.
Sorry for duplicating - probably succes solution is in answer form "ebassi" here GLib-GIO-ERROR**: No GSettings schemas are installed on the system (not tested yet)
Settings schemas (which are used in GTK in more places than just the file selector widget) cannot be statically linked into a binary: they have to be installed in a well known location (controllable via the $XDG_DATA_DIRS environment variable) and they have to be compiled into a cache.
GTK's dependencies like Pango and GDK-Pixbuf also use ancillary files and loadable modules that are not strictly compatible (unless you're willing to spend time on it) with static linking.
The usual recommendation for only providing a single executable for your application is to have a self-extracting installer that contains all the installed files necessary to running a GTK application, and avoid static linking.
I don't think it's possible to create just one .exe file (without any other files) with GTK+. Maybe only when you recode the GTK and it's dependencies - which is not an easy task to do.
The best solution I found is to put all schemas (and also icons for your GTK+ app) in the same location where your .exe file is placed:
EXE_LOCATION\program.exe
// For icons:
EXE_LOCATION\share\icons\hicolor...
// For schemas
EXE_LOCATION\share\glib-2.0\schemas
Then you deliver these files together with your .exe file and with all needed .dll files.
About the native file chooser in GTK+: It also needs the schemas - at least on Windows OS.
I have mostly used kate, vim etc to code and just pure console and gdb (rarely) to test. I want to start using eclipse, mainly for ease of looking up stuff, and hopefully (while not super important,) run the GUI debugger.
However, I don't want eclipse to touch my real project folders (it should change the code, obviously, but don't want it to create any configuration folders etc). Is that possible? I was thinking to create a workspace on a different folder, and add sources from my project path. But this seem to be complicated without any experience with eclipse when handling Makefiles etc!
Anyone has done something similar? any guidelines?
Yes, this is fairly straightforward. Instead of creating a standard C Project that creates and manages makefiles for you, use the "Makefile Project with Existing Code" instead.
If you don't want the .cproject, .project, etc files intermixed, create the CDT project in an empty directory and use Linked Files and Folders to pull in what you do want in the project.
If you do try to do a Build within Eclipse it will do "make all", but if you don't have a Makefile you get this (same for clean):
make all
make: *** No rule to make target `all'. Stop.
What I have done is for projects that don't have a make equivalent (like CPython extension) is to write a trivial Makefile that delegates all and clean targets to my real tool.
Once you have the project created, you will need to configure it to get all the goodness of CDT. The CDT Indexer and Scanner needs to know about your compiler settings (includes and defines really). There are two ways of delivering that information:
Run a verbose build (i.e. with gcc command line arguments echoed) from within Eclipse (e.g. use trivial Makefile described above). CDT will parse that output and automatically pick up compiler options used.
There are a number of ways that CDT can learn about what your settings are, to configure how they are picked up, head to project properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. and adjust the sources in the Providers tab:
In the project properties, edit the C/C++ General -> Paths and Symbols properties. You may have to do this if CDT cannot determine all your settings in Step 1 too. This is a screenshot of some of those settings: