Windows: Eclipse & googletest - eclipse

I am trying to setup googletest in Eclipse. I really got stuck.
I downloaded the current googletest version 1.13.0. fuse_gtest_files.py is not included in this version (which is often referred to in instructions).
Anyway, I set up an empty c++ project (GCC C++ compiler). Then I added the include paths for the gtest header files (compare picture).
enter image description here
Afterwards, I tried to compile the code. I got the error message "undefined reference to `testing::InitGoogleTest(int*, char**)'" - Reason: It could not find the related .cc files.
#include "gtest/gtest.h"
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
So I added the source Location of the cc files (compare Screenshot).
enter image description here
Now, the function is found. But I get a bunch of errors "multiple definition of xx"
C:/xxx/tools/googletest-1.13.0/googletest/src/gtest-assertion-result.cc:45: multiple definition of testing::AssertionResult::AssertionResult(testing::AssertionResult const&)'
src\gtest-all.o:C:/xxx/tools/googletest-1.13.0/googletest/src/gtest-assertion-result.cc:45: first defined here.`
Does anyone has an idea?
Thanks
Jenny

Related

Compiler generates FPU instructions

I realize a CMSIS Project solution with VS Code but I've an error on an include file :
#include "stm32f10x.h"
And I've got this error :
In included file: "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"clang(pp_hash_error)
core_cm3.h(90, 6): Error occurred here
The path of this file is here :
C:\Users\"name"\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.0\Device\Include
But I think I forgot something during the configuration.
I justa want to build my C file but VS code doesn't make the link between my .h and my CMSIS project.
You are never supposed to #include "stm32f10x.h"
You only #include "stm32f1xx.h" and it will include the other headers you need.
You must also define a macro on the command line, one of STM32F101x6, STM32F101xB, STM32F101xE or STM32F101xG.
For most compilers you can define this with an argument like -DSTM32F101xB.
After that you will need particular command line arguments that match your chosen processor, such as -mthumb -mcpu=cortex-m3 -mfpu=none.
Maybe your error was specifying an incorrect -mfpu=.

Eclipse CDT, CMake and GLIB

I have a simple c file:
#include <glib.h>
int main(int argc, char *argv[])
{
guchar temp = 1;
GSList *list = NULL;
list = g_slist_append(list, (int []){1});
}
and a simple CMakeLists.txt file:
PROJECT (GLIB_TEST)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_C_COMPILER "/usr/bin/c99")
find_package(PkgConfig)
pkg_check_modules(GLIB REQUIRED glib-2.0)
include_directories(${GLIB_INCLUDE_DIRS})
add_executable(glibtest glibtest.c)
target_link_libraries(glibtest ${GLIB_LIBRARIES})
I use
$ cmake -G'Eclipse CDT4 - Unix Makefiles' -D CMAKE_BUILD_TYPE=Debug ../src
from a "sibling" build directory. I then import the project into eclipse.
All seems well except that certain definitions do not resolve. Specifically in this case, neither "guchar" or "GSList" get resolved even though glib.h is definitely included via "/usr/include/glib-2.0" in the projects "C/C++ Include paths and symbols (I have verified this).
The specific error is "Type 'guchar' could not be resolved" and "Type 'GSList' could not be resolved".
From the command line "make" succeeds without error. Any ideas?

Adding QtCore Library in blackberry 10 sdk

Hi guys I am creating a simple game using cocos2d-x and blackberry. I need some place to store my game settings, something similar to shared preferences in ios and android. I found some code using qsettings, but the problem is I am not able to add the QtCore library.
I add the library using RightClick->configure->add Library and Standard BlackBerry Platform Library. The library gets added successfully.
#include "dataProcessor.h"
#include <QtCore>
void dataProcessor::setup(){
QDir dir;
dir.mkpath("data/files/text");
dir.cd("data/files/text");
}
but when I compile the above code, I get the error C:/Users/I076636/Documents/target_10_0_9_1673/qnx6/usr/include/qt4/QtCore/qatomic.h:45:28: fatal error: QtCore/qglobal.h: No such file or directory
But I noticed 2 things,
1.qglobal.h file is there inside the QtCore directory I have included.
2.inside qatomic.h if I change
#ifndef QATOMIC_H
#define QATOMIC_H
#include <QtCore/qglobal.h>
#include <QtCore/qbasicatomic.h>
into
#ifndef QATOMIC_H
#define QATOMIC_H
#include <qglobal.h>
#include <QtCore/qbasicatomic.h>
the error for qglobal goes and now the same error comes for qbasicatomic.h.
I think it is something simple like incorrect mapping between QtCore keyword and include directory or something..
Please do have a look.
The IDE is made on eclipse.
You can understand what is going wrong if you look closely at the error message:
/target_10_0_9_1673/qnx6/usr/include/qt4/QtCore/qatomic.h:45:28:
fatal error: QtCore/qglobal.h: No such file or directory
The error isn't in your inclusion of QtCore, but is occurring inside QtCore/qatomic.h, on line 45 (you can find this file in the [YOUR BBNDK DIRECTORY]/target_10_0_9_1673/qnx6/usr/include/qt4/QtCore/qatomic.h):
#include <QtCore/qglobal.h>
qatomic.h is already in the QtCore directory, and you'll find a qglobal.h directory there as well. So what this means is that qatomic.h expects the parent directory to be on the include path, so that including <QtCore/qglobal.h> will work.
So you just need to add [YOUR BBNDK DIRECTORY]/target_10_0_9_1673/qnx6/usr/include/qt4 to your include directories.
Do it like this:
Right click over your project in Project Explorer and choose Properties
Expand the tree to C/C++ General / Paths and Symbols
Change the Configuration in the Paths and Symbols frame to [All configurations]
Click the Includes tag and select GNU C in the Languages list (or do this for every language).
Click Add... and type ${QNX_TARGET}/usr/include/qt4 and press OK
Click Add... and type ${QNX_TARGET}/usr/include/qt4/QtCore and press OK
Now your include of #include <QtCore> should work.
Next up: linking errors ;-)
It sounds like your BB10 NDK did not get installed properly, or your project wasn't set up properly. If you expand your project and the Includes you should see (along with others):
<NDK_INSTALL_LOCATION>/target_<VERSION>/qnx6/usr/include/qt4/QtCore

Eclipse giving me Invalid arguments ' Candidates are: void * memset(void *, int, ?) ' though I know the args are good

I am getting an invalid arguments error in eclipse, though I am confident my arguments are good. The suggested arguments contains a '?' which I think may indicate the problem, though I do not know how to fix it.
I have done my best to copy the example I saw here:
http://www.cplusplus.com/reference/clibrary/cstring/memset/
In order to be certain that I am getting the args right.
#include <stdio.h>
#include <string.h>
void foo()
{
char str[] = "why oh why does my IDE give me errors when I know my args are good?";
memset(str, '-', 4);
puts(str);
}
Eclipse gives me the following error on the memset line:
Invalid arguments ' Candidates are: void * memset(void *, int, ?) '
What could be causing this? And what is up with that '?' as the 3rd arg?
Thanks in advance!
PS: Just noticed I am getting similar errors when I try to use operations like malloc, calloc, etc.
In Eclipse:
right click the project
click properties
Expand "C/C++ general" the item in the left hand tree view by clicking the arrow, (just clicking the item itself does not expand the suboptions)
From the suboptions select "Preprocessor Include Paths, Macros etc."
Click the "Providers" tab
Check the box next to "CDT GCC Built-in Compiler Settings [ Shared ]".
Edit:
The reason this works is that there are a bunch of default includes and defines that the compiler silently adds behind the scene when you compile. These instructions get eclipse to grab these otherwise silent preprocessor directives so that it's own indexer is using the same settings
The following method resolves the same problem that I was having. (on eclipse 4.2)
Clean your project (Project -> Clean)
Reindex files (Project -> C/C++ Index -> Rebuild)
Rebuild your project (Project -> Build All)
I think it is something to do with your Eclipse setup, somehow.
Taken standalone, that fragment compiles under GCC (G++) 4.7.1 on Mac OS X 10.7.5 with the command line:
g++ -O3 -g -Wall -Wextra -c ms.cpp
The only surprising thing about the third argument to memset() is that it is of type size_t, but the headers are supposed to declare that, so it should not be an issue.
If you're using malloc() et al, you will be including <stdlib.h>, of course. There is also room to argue that you should be using <cstdio>, <cstring> and <cstdlib>, but that shouldn't stop the code you presented from compiling without error.
If you're working with Visual Studio, size_t is defined as
typedef unsigned __int64 size_t;
In previous versions of the Eclipse CDT, __int64 was not defined. You can fix that issue by adding into C/C++ General -> Paths and Symbols -> Symbols
Symbol: __int64
Value: long long
Or you can upgrade your Eclipse CDT version
I've been using a 3rd party C++ library for BeagleBone development and I tried every possible way to include it (as preprocessor includes, source folder, assember includes, library includes, C++ compiler includes, C compiler includes etc). Refreshen, reindex, clean and built for every change I attempted. I even deleted the project and copied only the .cpp and .h files over to a new project.
I finally found the problem in my setup and rectified it as follows.
Right-click the project > Properties > C/C++ Build > Tool-chain editor > Current Builder:> Select CDT Internal Builder
I'm using g++, for your information.
I had a similar issue with the Eclipse CDT. But in my case the thing was that I had put the using namespace std; statement in a several headers. And in some combination of conditions, when I included all of this headers the Eclipse had such the behavior.
I had a similar issue when compiling someone's code, and the problem was the code style. They defined some methods in this way:
// ... Inside a class
static void
sleep( u32 ms );
I guess this is GNU style. Just changing the declaration to
static void sleep( u32 ms );
removed the issue.

unresolved external symbol - Error using Matlab API

I'm trying to read a .mat-file in C++ with MSVS 2008 but when building a simple program I get the following error:
1>ex3.obj : error LNK2019: unresolved external symbol _matClose referenced in function _main
1>ex3.obj : error LNK2019: unresolved external symbol _matOpen referenced in function _main
I've researched Google as well and it seems that the compiler can't link to the libraries needed for using this functions (matOpen and matClose). I never used an external library before but I tried everything I found in Google to add the Matlab libraries. I did the following:
TOOLS --> Options --> Projects and Solutions --> VC++ Directories --> Show directories for: include files --> then I added the path of the matlab include directory --> C:\Program Files\MATLAB\extern\include
I did the same with the library files: C:\Program Files\MATLAB\extern\lib\win64\microsoft
I also did that for the project:
Right click on the project --> Properties --> Configuration Properties --> C/C++ --> General --> Additional Include Directories --> and added "C:\Program Files\MATLAB\extern\include\win64"
Then I did the same at Linker --> General --> Additional Library Directories --> and added "C:\Program Files\MATLAB\extern\lib\win64\microsoft"
So I really don't know where the problem is. Here is the source code I'm trying to build:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <mat.h>
int main(int argc, char *argv[])
{
const char *file = "mozart_part1.mat";
MATFile *pmat;
pmat = matOpen(file, "r");
if(pmat == NULL)
{
std::cout << "Error: could not open MAT-file!";
return(1);
}
matClose(pmat);
}
Can you see or guess any mistakes I made
Take a look here.
Go through the steps.
What I think you've missed is step 7:
7.Locate the .lib files for the compiler you are using under matlabroot\extern\lib\win32\microsoft or matlabroot\extern\lib\win64\microsoft. Under Linker Input properties, add libmx.lib, libmex.lib, and libmat.lib as additional dependencies.
Edit:
Both Matlab and Visual C++ should be either 32bit or 64bit. There are two options:
Find these 3 lib files from another Matlab which is 32bit. Direct your linker there instead.
Make your Visual C++ 64bit. See here how it's done.
Solution:
What eventually worked was option 2, using this link with instructions.
I solved the Problem!
#Michael Litvin: you were right! I didn't know that you have to switch MSVS 2008 to x64 platform.
As the Matlab libraries are provided as x64 binaries you have to switch your MSVS compiler to x64 as well. I followed these steps to do that: http://software.intel.com/en-us/articles/configuring-microsoft-visual-studio-for-64-bit-applications/
Thanks for you help!