So I'm getting into c++ and I recently built a logger class ie print any type to the screen and/or to a log file. I built it as a dll and the output files are
console.h
console.lib
console.dll
I then imported these files as additional includes to another project and it works, only in debug mode (in which it was built) I wish for it to work regardless of build config. How can I accomplish this. An example, I recently used the GLFW library and can build in both how was it compiled for this to work.
If I correctly understood you're trying to link same version of your lib/dll with both debug and release configs of your app.
In general case you need two versions of your lib/dll files, debug and release, and link with the one that matches your application configuration, so for debug config of you app link with debug config of your lib/dll, and release with release.
The most possible problem of using mixed configs (like debug dll with release exe) is allocating memory in one domain and releasing it in another.
EDIT:
To elaborate, the problem can be allocating memory in your DLL and releasing it in your EXE, or vise versa. This doesn't work, at least with VS C-Runtime. For more details, see: https://stackoverflow.com/a/45806858/453271
Related
I am trying to build an application file in release mode in Visual Studio 2015. The issue is that I need to use the Multi-threaded DLL run time library option. When I create the application and try to run it on a different computer I get various missing dll errors like msvcp140.dll and vcsruntime.dll. Is there a way to create an application file such that it has everything it needs and can independently run on any computer.
Under "Libraries" you should select
"Debug Multithreaded (/libs:static /threads /dbglibs)" for all your libraries. All the needed dll's will now be linked to your application. The executable will be somewhat bigger, but the application should work on any windows computer. You can use this option for both the debug and the release version. Keep in mind though that you may still run into problems if you're creating your own dll's that depends on other external dll's (which they often or always do). I.e. in order to be safe; do not create your own dll's.
You have to keep dependencies beside the exe(compiled) file. for this job, you can copy them in the exe directory, or set environment variable. Additionally, I suggest using cross platforms libraries, such as QT.
I regularly use log4cplus, but I have encountered a new problem.
I have a windows application which uses a dll (LoadLibrary)
They are built on different compilers, but use dlls with the same name (including log4cplus.dll) also built on different compilers. The app and all the dlls it uses are built in one environment (vs2008). The dll and all the dlls it uses are built on another environment (vs2013).
LoadLibrary failed until I changed the application to pass the LOAD_WITH_ALTERED_SEARCH_PATH flag to LoadLibraryEx, which appears to allow the dll to load its own dependencies successfully, except now I get these runtime errors
log4cplus:ERROR PropertyConfigurator::configureAppenders()- Cannot find AppenderFactory: log4cplus::RollingFileAppender
log4cplus:ERROR PropertyConfigurator::configureAppenders()- Cannot find AppenderFactory: log4cplus::ConsoleAppender
log4cplus:ERROR PropertyConfigurator::configureLogger()- Invalid appender: ROLLING
Logging works for all applications built in either environment.
Logging also works for this app and dll both built in the same environment.
I changed the dll to statically link log4cplusS.lib, but I still get the same errors.
First off, use the same compiler for everything. It is basically impossible to make things work when using different compiler versions. Once you are compiling everything with the same compiler, try to solve other problems, if any still remain.
Using Visual Studio 2013, I have created a Windows Phone (8) app which references a Windows Phone Runtime Component which in turn references a C++ DLL (all in the same solution). Without doing anything explicitly, the DLL would not get deployed to the target platform, and so there would be a runtime error as the runtime component attempted to load the DLL. I got around the problem by adding the DLL (the DLL project output) as an additional deployable file to the runtime component project. (As one might add any other data file)
While my hack works, I'm sure it is not the correct thing to do... because it is a reference to the debug DLL (no release DLL built thus far), and if I were to do a release build for the solution, the same debug DLL would be deployed, where it ought to be the release version.
What is the proper/best practice way to ensure that the correct (debug vs release) "sub" project DLL gets deployed with a phone app?
The right way is to include the dll project in your solution and than in the References of the Solution Explorer via the opening dialog.
I'm running carbide 2.7 with 9.3 SDK FP2. I have two projects, one is an animation dll TARGETTYPE ANI and another is an exe that will invoke it.
what is the way that i should debug this in the emulator? what do i need to change so both the exe and dll are deployed in the emulator and i get to debug them?
Well I don't have access right now to a working Carbide, but you will need surely the followings:
load both projects to your workspace
at the debugger configuration (something like Debug... or Debug settings, I don't remember), there is a "load symbols" options and then you have to select "from all projects in the workspace" or at least tick your two projects.
sometimes this does not work. You can try to load the symbols at runtime, there will be a "load symbols from" somewhere in the menu system, you have to select your dll binary here.
try to put a breakpoint at the entry point of your dll
if you debug on the device ensure that you copy the debug variant of your binaries into the sis
Debugging multiple binaries in carbide is a bit of matter of luck, sometime you succeed sometime you don't as this part of carbide has some bugs. However it is definitely possible, I did it already in the past :)
the question is how to configure in c++ builder 2010 compiler and debug option to output just one exe file, and all the other inside of that, so that i can easily use program on other maschine without installing them, with just runing exe file.
With all versions of C++Builder you don't need to make an installer for this, (although inno setup is simply brilliant if you do require one).
Just select the following project options:-
Project/Packages:, Build with Runtime Packages = DISABLED
C++/Linker: Dynamic RTL = FALSE
That's it. You will get a single exe with no dependencies (apart from any 3rd party DLL's you use. All your VCL components (including third party ones) will get statically linked.
I use this mode for all production builds (although I do then use Inno Setup installer to manage the install/removal process for customers).
In addition to Roddy's answer:
Do not forget to disable CodeGuard (Project->Options->Codeguard) or your program will fail on any machine that does not has the CodeGuard DLL's installed !