Finding object files compiled with WholeProgramOptimization flag - visual-c++

When linking my final .exe file I receive error: C1047 The object or library file XX.lib was created by a different version of the compiler than other objects like YY.lib rebuild all objects and libraries with the same compiler.
According to the documentation: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1047?view=msvc-170
It happens when some object files are compiled with /GL or /LTCG flags.
YY.lib is an external library. It is C library, compiled with different version of Visual Studio. But it should be fine. It has no /GL nor /LTCG flag enabled.
XX.lib is another static library. I partially control how it is created. It contains many third-party libraries also inside.
Now I need to somehow figure out which .obj files inside XX.lib were compiled with /GL flag (to remove this flag and fix the issue). Is there any way to find out which .obj files were compiled with the /GL or /LTCG flag enabled without direct access to source/build systems of those libraries ? (I assume it should be possible as linker is able to determine it). But I can't find where this information is stored. I can unpack the static library to individual .obj files. But using e.g. dumpbin I don't see any info about /GL or /LTCG flag.

Related

How to link using an external pdb?

In VS2012, I'm statically linking with a precompiled .lib, and need to also use that lib's .pdb file for debugging.
How can I tell the linker that it should use that external pdb file?
If you created the static lib with /ZI or /Zi (see project settings for C/C++ -> General -> Debug Information Format), then the $(IntDir)vc$(PlatformToolsetVersion).pdb file is created. The path is defined by /Fd.
A linker that uses the static library usually also refers to this pdb file. If you link an executable with the static lib and the linker can't find the pdb file you should get the error like this
LNK4099: PDB 'vc1xx.pdb' was not found with 'foo.lib(foo.obj)
So what you want is the default. You may turn on verbose linking to see what happens to your symbols.
Microsoft always ships a PDB file with their static libraries named the same way like the static lib. So you find a libcmt.lib and a libcmt.pdb

CMake to create a exe and lib with (prepackaged headers and dlls)

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(ImageProc)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
find_package(PCL 1.2 REQUIRED)
find_package(OpenCV REQUIRED)
add_definitions( -fPIC -Wall -O3)
include_directories(${PCL_INCLUDE_DIRS})
#link_directories(${PCL_LIBRARY_DIRS}) Dont think neccesary..
add_definitions(${PCL_DEFINITIONS})
add_executable (ImageProc svm.cpp ImageProc.cpp testImageProc.cpp)
target_link_libraries (ImageProc ${OpenCV_LIBS} ${PCL_LIBRARIES})
add_library(ImageProcLib STATIC svm.cpp ImageProc.cpp)
target_link_libraries (ImageProcLib ${OpenCV_LIBS} ${PCL_LIBRARIES})
Currently, I run this and open with VS C++ and generate an exe and lib.
The exe runs on my machine.
Current limitations:
When I pass the exe to my friend, he cant run it on his machine as he gets hit by host of missing dlls.
When I use the lib files, to create a new project in VS C++, there is a fatal error in not finding a header file.
I know, I can manually add all the dlls and or package all the header and library files for the lib. But it is definitely cumbersome and ugly also.
Question:
Does CMake offer a way, so that when compiling into
An exe (it will automatically find all the necessary dlls into bin directory)
Into a lib (it will automatically source out all the header files and also the neccesary library for the linking part into the lib directory)
Preparing your package for deployment on other development environment can still be a tough task. You will need to setup your own interfaces/API correctly and will need to deal with cross-dll issues, different runtimes, etc.
However, there are a few tools from CMake at your disposal:
Check out the Install and Export. You can use it to specify (in your CMakeLists.txt) which files are necessary for deployment. This way, you can mark which header-files, but also which targets (libs and exes) should be deployed.
Also take a look at CPack in combination with NSIS, which can be used to build NSIS installers of your project.
Together with the InstallRequiredSystemLibraries and BundleUtilities you can then prepare an install or package target. See also this and this question demonstrating how third-party dlls can be added to such a deployment package.
InstallRequiredSystemLibraries is very useful for appending vcredist to your own package installer, which you will surely need if you are installing your project on a non-development pc.

Strange files : *.dll.a * .la What are they? ( VLC windows build ) How to use them on Windows if possible?

I wanted to write small streaming software using VLC compoents on windows. So i look for : lib and headers file for VLC on windows. Instead of compiling it , to make it faster i looked for ready builds for windows. And i found on: http://nightlies.videolan.org/build/win32/last/
I download it (debug) : Find include file directory and lib. But lib directory contains trange (at least for me) file extensions such as libvlc.la and libvlc.dll.a
What are they? Can i use them in Visual C++?
The .la files are libtool convenience libraries, they're useless and only cause trouble (in this case).
The .a files are (import) libraries for GCC/MinGW, just like .lib for MSVC.
VLC can only be built with GCC, because MSVC lacks the proper C99 support. So all debug info will be generated by and for a GNU toolchain (GCC/Binutils/GDB). If you want to use the proper DLL in Visual Studio, you should be able to create an import library from the included .def file and the dll.

CUDA CUDPP .so building

I want to use CUDPP library in my project. I've downloaded sources from project page. Unfortunatly, when I ran "make", there was only static library build. I've looked into Makefile files and haven't found any dynamic lib configuration. I don't want to keep static library with the project - it's totally non-portable way.
My question is: how can I build .so dynamic library of CUDPP, without writing my own Makefile/compiling it manually? Maybe someone already did it?
EDIT: I've replaced "g++" with "g++ -fPIC", "gcc" with "gcc -fPIC" and "nvcc" with "nvcc -Xcompiler -fpic". When I unpack obj files from archive, and link them to shared lib, I've got no error. However, my application crashes at start, when linked with this library.
when you compile pass the flag -Xcompiler -fpic to nvcc. If you link against any cuda libraries make sure you've linked to the shared libs, otherwise you can't link it. Hopefully that's all you need.
Are you also using -shared to create the library? You shouldn't need to extract anything from an archive if it is working correctly.
If you run ldd on your executable it will show you what dynamic linking is required by the app and you can check that the -fPIC etc. worked correctly. Also make sure that the .so library is on your LD_LIBRARY_PATH (sorry if that's obvious, no harm in checking).

How do I link assembly with the C library with MSVC++ linker?

I found a simple assembly tutorial online that uses some C functions. I've already used NASM to generate a .obj file but I'm having trouble linking against the C library from the command line. How do I do this with link.exe?
I'm using Visual C++ 2010 Express.
Thanks for the help.
Specify one of the run-time library options: /MD (multithreaded DLL run-time) or /MT (multithreaded static run-time).
In debug builds, specify /MDd or /MTd respectively.

Resources