Recently I discovered a problem on the midas and I fixed it, the problem now is that I want to use MidasLib not the midas.dll and with the source code I'm only able to build the DLL.
The source is C++ and I have very few knowledge with it. I know the MidasLib.pas uses internally midas.obj, so I need to create it to statically link the midas to my application. How to do it on C++ Builder? (XE)
When you compile C++ code, the compiler creates an .OBJ file for each .CPP/.C file you have and saves them somewhere on your computer. What happens in most cases is that one would run a linker on all of those .OBJ files to join them into a single EXE or DLL, but in your case you don't need those results. Your C++ Builder is, like most programming IDEs, automatically doing both the compilation and linking.
If you just want the .OBJ, you need to find where in your project folder C++ Builder is placing its .OBJ files (called its "intermediate output", typically, as it is the intermediate step between compilation and linking). So you must have a source file called midas.cpp or midas.c that produces a corresponding output file called midas.obj.
Related
I am trying to run codeql on Chromium among a few other open-source software, and I was wondering if it is possible to compile a single file from the full source code, because my machine takes a long time to compile such huge codebases.
For example, is it possible to compile the media/filters/ffmpeg_video_decoder.cc file only?
Compiling is not the issue. If you only compile one source file, it will be missing several functions that would be added to the final binary in the linker phase.
https://en.wikipedia.org/wiki/Linker_(computing)
Only compiling one file will (most probably) not make a working binary, as you need a main function along with all the other code.
From a quick CTRL-F through the source code, a main function, which is critical for the program to run, is absent from the file you mentioned, so you definitely won't be able to make a working executable.
If you're making a .lib (library) file, it might work, although you're almost certainly going to run into undefined references, as the code is broken apart among many files.
My question is kinda similar to this one: How to generate an executable from an llvm::Module?. But as the answeres there are from 2012, and I'm not sure if anything has changed.
So I've got an LLVM::Module and want to produce an executable from it. I know that I can build an object file from it and invoke a linker on that .o file to get an executable, but I don't want the I/O overhead of reading and writing a intermediate .o file.
I'm wondering if there is an API in the LLVM project that I can use to generate a exec. from a module. Is the llvm::Linker class maybe a good point to start?
Let say we have a large code base and we are doing development in C++. Do we have to recompile everytime in order to test the code?
If yes then it is going to take ages to do development.
What's the solution to this problem?
Yes, you'll definitely need to compile C++ code if you want to test it. C++ code can't be executed without being compiled.
However, if you organize your project smartly, compilation could take only a few seconds, or maybe up to a minute, even if there are thousand (or even more) of files.
By default, your build system will run an incremental build, except if you explicitly request a "rebuild" or did a "clean" previously. It will then invoke the compiler/linker accordingly and make sure it compiles/links only what needs to be (if a cpp file did not change, no need to compile it, this is all based on file timestamps, if the "object" file (generated) is older than the cpp file (source), the build system knows it's up-to-date and won't generate it again. If you use Visual Studio and/or CMake or whatever IDE, build system, they all support that!
Additionally, you can follow some guidelines to make this even faster:
Firstly, organize your project in modules (libraries), ideally with dynamic link. Then when a file from a library is changed, only this library needs to be compiled (other libraries or programs using the modified library won't have to be compiled again).
When you'll modify only an implementation file (cpp file), only this file + link of the module using it will be needed.
When you'll modify an header file (h file), all cpp files including it will need to be recompiled, so you must be careful to optimize your includes. Prefer forward declaration (see why here)to includes whenever it's possible (else, your header becomes a dependency of all cpp files using the other header file including yours...as a cascade, modifying this header file will end up requiring compilation of tones of cpp files). Don't include files you don't need (because it will fire a new useless build when the header file changes). Possibly use precompiled headers to speedup compilation.
Note: As commented, there are apparently some tools that can interpret C++ without compiling it...but that's not what C++ was designed for at the first time. And I doubt they will be fast as compiled code at runtime....so you'll probably save 20sec of incremental build time and then loose minutes at runtime....
I am new to programming with C++. So I am trying to inspect other's code to learn. I started inspecting a new prototype which has a function named myFcn. Its comment lines describe it requires mk.h, mk.lib and mk.dll files to be compiled. The project was successfully built. But when I go over the calling line of myFcn and press F12 (go to definition), the declaration prototype of myFcn appears and hitting again F12 does not bring me the body of the myFcn. I guess the function definition is in the mk.lib or mk.dll files. How can I find the body of the function?
EDIT 1:
If I had several dll and lib files, could I recognize the file that myFcn was compiled in?
It seems that the function you are trying to use is compiled in the library which you use.
The purpose of this system is to let people use your functions without the need for them to edit them or understand their source code. This means that the author of the library has written the function, and compiled it into a library (.dll, .lib and .h).
By including the .h file in your project, and linking the .lib at compilation and the .dll at runtime, you can use this function without the need to ever see more than the header file.
If you wish to understand the code of this function, go to their website, and see if they provide the full source code.
Edit based on edit of question: As far as I know there is no direct way to see which header file links to which library. It is possible to view which functions are in a certain library. On Linux this is the 'nm' command for .a files (gcc libraries). For Windows some methods are described here: How to view DLL functions?.
The function body is likely to be compiled, if then you can't see the source code of it.
I'm importing a TLB file into my project since I'm using a COM DLL. A TLB file is a binary file, which I need to compile my source code and so I was wondering if it's good programming practice to commit it to the repository.
Yes, it's ok to put binary files in a source repository. The rule sometimes called 'do not put binary files in a source repository' should better be called 'do not put temporary files or files that are a compilation result in a source repository'. Basically anything that can't be produced from other files and is relevant for the project itself (i.e. no editor preference files) can be put in a repository.
A type library is normally created by midl.exe from an interface definition language (IDL) source file. Or from a utility like Tlbexp.exe or Regasm.exe which can generate a type library from a .NET assembly. If you don't have the source for the type library then there's little else you can do but check-in the .tlb. Note that a type library is very commonly embedded as a resource in the COM server. So checking in the binaries is an option too.
Note that it is technically possible to reverse engineer the IDL from the type library with the Oleview.exe File + View Typelib command. Not so sure that's useful when you don't actually control the source.