I am currently working on a project on windows 10 and was asked to use some c++ code for it. The code was written with plattform independence in mind. So I used the given cmake files to build a visual studio solution (VS 2015 Update 3). But when I try to build the solution it gives me over 900 errors and warnings.
The same project was successfully build on a mac using cmake and g++. The project itself uses a Qt gui and some additional libaries like boost.
To understand the errors you have to know, that the solution consists of 5 projects: ALL_BUILD, iModControll, iModDaemon, iModView and ZERO_CHECK
There are a lot errors like:
missing type specifier - int assumed. Note: C++ does not support default-int
inconsistent dll binding
declaration not found
unexpected token before ;
and so on...
You can see the full list here
I am very new to cmake and not an VS expert, so please help me to understand what went wrong here. Again: the code compiled perfectly under OSX.
EDIT:
I used mingw, as #MaxGo suggested. The errors and warnings were reduced after that. Here is what I have now:
warning: void DC_TermFunc()' redeclared without dllimport attribute after being referenced with dll linkage
void DC_TermFunc(void)
{
if(controller)
{
qDebug() << "Terminating iModSkynet";
runthread->terminate();
delete runthread; // This will delete the controller too
}
}
error: function 'void DC_SendData(char, char*, int)' definition is marked dllimport
IMODCONTROLLSHARED_EXPORT void DC_SendData(char oc, char* data, int length)
{
QByteArray qdata = QByteArray(data, length);
controller->sendBlenderCommunication(oc, qdata);
}
The other errors are similar. My question is: Are there any known issues when porting c++ source code to windows, why does it not show as many errors as in VS and what can I do to solve these errors?
CMake Configuration- Boost- Visual Studio - C++
Step 1: Download CMake installation file, install and save it in local disk
Step 2: Create 2 Folders in local disk a) Raw File b)Solution File
Step 3: Raw File folder- Create a Main.cpp file and paste your raw c++ code it it and save. Now in the same folder create a txt file named CMakeLists and paste the following code in it and save.
cmake_minimum_required(VERSION 3.7)
project (cmboosttest)
#find_package(Boost REQUIRED)
#include_directories(${Boost_INCLUDE_DIR})
add_executable(boosttest ${PROJECT_SOURCE_DIR}/Main.cpp)
Step 4: Open CMake choose Raw File folder in browse source and Solution File Folder in browse build.
Step 5: Click Configure. Once it succeeds, click Generate.
Step 6: When you open the Solution File folder, you can see the built solution file. Click on it and your program will open in Visual Studio. Now, build your program in VS.
Hope this helps!
Related
I am using Microsoft Visual Studio Professional 2017 15.9.29 when compiling a project.
Compilation goes well, but linker shows an error
LINK : fatal error LNK1181: cannot open
"H:\work\build\Release_x64\intermediate\plugin\Helper.obj"
I checked the file. It does not exist. Any reasonable thought would be helpful.
/P compiler option was on, and object files were not generated.
When I try to debug the file using "Step into new instance", Visual studio returns this in a new tab:
Symbol File Not Loaded
No symbol file loaded for asmcalc.exe
Symbol Load Information:
Binary was not built with debug information.
This is my assembly code in a file called "asmcalc.asm":
global main
section .text
main:
xor rax, rax
ret
I use the following commands to build the .obj then .exe:
nasm -f win64 asmcalc.asm -o asmcalc.obj
GoLink /console /entry main asmcalc.obj /fo asmcalc.exe
Which successfully creates the file, but the aforementioned error occurs when I try to run through visual studio.
Also, after looking at the disassembly, it does not contain the labels I had in the code, which I am not sure if they are supposed to be there or not (I am a beginner with NASM).
NOTE: I am following the tutorial here: https://simon-whitehead.github.io/2018/02/adventures-in-64-bit-windows-assembly-part-1/
Which says that my output should look something like this in the Immediate Window:
rsp
(Some hex address)
But it's blank for me.
EDIT: The file is not natively built on Visual Studio in MASM, it's built into a .exe that gets imported into Visual Studio then run using the debugger.
EDIT 2: One of the comments mentioned creating a symbol file to fix the issue, how would I do such?
I am trying to utilize the ffmpeg libraries in a program of my own and am having trouble linking them. Specifically, In my a basic program I am receiving fatal error LNK1120: 1 unresolved externals errors. The program is:
#include <iostream>
#include <libswresample/swresample.h>
int main()
{
std::cout << "Hello World!\n";
struct SwrContext* swr_ctx = swr_alloc();
if (!swr_ctx) {
std::cout << "Could not allocate resampler context";
}
}
I downloaded prebuild libraries from https://ffmpeg.zeranoe.com/builds/, specifically the Windows x64 dev package which includes the .def/.lib as well as .dll files.
I originally tried (and intend to ultimately use) cmake to generate the MSVC sln files. The cmake file is:
cmake_minimum_required(VERSION 3.5)
project(ffmpeg_jni)
# Find the JNI bits
find_package(JNI)
# Search for the ffmpeg libraries
set(ffmpeg_include_hint "ffmpeg-dev/include")
set(ffmpeg_lib_hint "ffmpeg-dev/lib")
find_path(SWRESAMPLE_INCLUDE_DIR libswresample/swresample.h PATHS ${ffmpeg_include_hint})
find_library(SWRESAMPLE_LIBRARY swresample PATHS ${ffmpeg_lib_hint})
add_library(swresample SHARED IMPORTED)
set_target_properties(swresample PROPERTIES
IMPORTED_LOCATION "${SWRESAMPLE_LIBRARY}"
IMPORTED_IMPLIB "${SWRESAMPLE_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SWRESAMPLE_INCLUDE_DIR}"
)
# Setup basic include dirs
set(includeDIRS
src/main/cpp
${JAVA_INCLUDE_PATH})
# Setup windows specific includes
set(includeDIRS
${includeDIRS}
${JAVA_INCLUDE_PATH}/Win32)
include_directories(${includeDIRS})
set(WRAPPER_SRC
src/main/cpp/logging.c
src/main/cpp/logging.h
src/main/cpp/main.cpp)
add_library(ffmpeg_jni SHARED ${WRAPPER_SRC})
target_link_libraries(ffmpeg_jni PRIVATE swresample)
The generated solution compiles and has proper access to the include files (Visual Studio can even take me to the declarations). The issue comes in the linking phase of the build where I receive:
error LNK2019: unresolved external symbol "struct SwrContext * __cdecl
swr_alloc(void)" (?swr_alloc##YAPEAUSwrContext##XZ) referenced in
function main
Thinking that I perhaps had something wrong in cmake since I am still pretty new with it I tried making a simple demo as a pure visual studio project following what I have found in countless online demos for adding an external library to a project. Specifically this included:
Adding the directory containing the header files to Properties->C/C++->General->Additional Include Directories
Adding the directory containing the .lib files to Properties->Linker->General->Additional Library Directories (Note that the cmake path did not do this but instead added the lib file via a relative path)
Adding the .lib file to Properties->Linker->Input->Additional Dependencies
At this point any searching efforts I undertake show me different people doing the same things which tells me I've been looking at this too long to find the answer myself and its something trivial that I'm missing/not understanding.
If you are compiling your project as c++, then include FFmpeg headers as below which tells your c++ compiler to handle FFmpeg headers as C instead of C++.
extern "C" {
#include <libswresample/swresample.h>
}
I'm trying to compile a SWIG project, and it keeps on giving errors like this:
swig_wrap.cpp(55): warning C4005: 'SWIGTEMPLATEDISAMBIGUATOR': macro
redefinition
And errors like this:
fatal error C1010: unexpected end of file while looking for precompiled
header. Did you forget to add '#include "stdafx.h"' to your source?
Compiler
Visual Studio 2015+Update 3.
SWIG v3.0.12
Add the following to your .i file:
%begin %{
#include "stdafx.h"
%}
This section injects code into the generated wrapper at the top of the file and you won't need to disable pre-compiled headers.
In Visual Studio, right click on the swig-generated .cpp wrapper file, and select "Not Using Precompiled Headers".
In my case, the wrapper file that swig auto-generated was swig_wrap.cpp.
You can leave precompiled headers on for the entire project.
For more info, see nabble.com and Fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Appendix A: SWIG could be fixed to avoid this!
Another way to fix this is to manually add the line "stdafx.h" to the start of this file, but unfortunately, every time swig is run it will remove this fix! There is a way to fix this, but its not at all obvious (see the other answer).
I'm using the new cross-platform tools in Visual C++ 2015 to build a native shared library for Android.
I had the NDK (r10d) installed before installing VS2015 so I chose not to install the NDK in VS's secondary installer. Instead, after installation I set the NDK path under Tools > Options > Cross Platform > Android.
I had a problem with VS not finding the toolchain binary - it was looking for arm-linux-androideabi-gcc.exe under [NDK_ROOT]\toolchains\arm-linux-androideabi-4.9\prebuilt\windows\bin while in my installation the file was in [NDK_ROOT]\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin. To remedy that I just renamed the windows-x86_64 directory to windows.
Now the problem is that build errors do not propagate to the Error List view. Instead, I get a single error in the Error List:
Severity Code Description Project File Line Source
Error MSB6006 "arm-linux-androideabi-gcc.exe" exited with code 1. pexeso-android C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Application Type\Android\1.0\Android.Common.targets 194 Build
The only place I can view the actual errors is in the output window:
ANDROID_HOME=C:\Dev\Android\android-sdk
ANT_HOME=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Apps\apache-ant-1.9.3\
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_05
NDK_ROOT=C:\Dev\Android\android-ndk-r10d
pch.h
PexesoAndroid.cpp
PexesoAndroid.cpp: In function 'jint JNI_OnLoad(JavaVM*, void*)':
PexesoAndroid.cpp:7:9: warning: unused variable 'jcPexeso' [-Wunused-variable]
jclass jcPexeso;
^
PexesoAndroid.cpp: In constructor 'PexesoAndroid::PexesoAndroid(JNIEnv*)':
PexesoAndroid.cpp:26:2: error: invalid conversion from 'void (*)(jstring) {aka void (*)(_jstring*)}' to 'void*' [-fpermissive]
};
^
PexesoAndroid.cpp:24:18: warning: unused variable 'method_table' [-Wunused-variable]
JNINativeMethod method_table[] = {
^
PexesoAndroid.cpp: In function 'jint JNI_OnLoad(JavaVM*, void*)':
PexesoAndroid.cpp:15:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
But this view is quite useless since, for instance, I cannot double click an error and have the IDE jump to the relevant line and source file.
Is this really what they meant when they said VS will be cross-platform?