Eclipse CDT, CMake and GLIB - eclipse

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?

Related

Windows: Eclipse & googletest

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

clang makes recompile everithing at each build in cmake

Here is a small c++ code, adapted from the tutorial Step 1 of CMake :
// tutorial.cxx
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello World" << std::endl;
return 0;
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
# set the project name
project(Tutorial)
# add the executable
add_executable(Tutorial tutorial.cxx)
I used the extension of vscode CmakeTools, and I noticed that every time I build the project, it recompiles everything, even if nothing was changed. After some investigations, I found that the configuration of the project is made by vscode using this command :
/usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/clang-10 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-10 -H/home/user/Bureau/projet/step1 -B/home/user/Bureau/projet/step1/build -G "Unix Makefiles"
(and if I configure by hand in the terminal with this command, it has the same behavior).
I noticed that if I configure the build directory without the option -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-10, there is no problem afterwards: if a make if nothing has been charged in source, it doesn't recompile.
I have actually 2 questions :
Why does the option CMAKE_CXX_COMPILER:FILEPATH induces such a behavior?
How to configure vscode so it doesn't use this option anymore?
EDIT :
I tried to configure the project with another compiler (in the list, vscode proposes Clang10, GCC 8.4.0 and GCC 9.3.0). With Clang all is recompiled at each time, but this is not the case if I take GCC.
This answers my second question: use another compiler.
But still, I wonder why does Clang recompile everything ?

c++ linux eclipse function runtime_error could not be resolved

in centos eclipse. Got a bug says "function runtime_error could not be resolved". I added -std=c++11 or -std=c++0x in the settings and rebuild the index. (see Multiple "could not be resolved" problems using Eclipse with minGW )
it still shows a bug in the CDT.
But in my makefile I added -std=c++0x it got compiled with no error.
the line has the bug is
throw runtime_error("error msg");
I included those header files
#include <cerrno>
#include <system_error>
using namespace std;
void main()
{
throw runtime_error("blabla");
}

compiler errors using Boost.Python with macports Python.framework

This might be a very dumb question...
I'm trying to use Boost.Python in an Xcode project (boost 1.50, xcode 4.4, OS X 10.8). I installed both boost and python through macports. I dragged the macports Python framework (/opt/local/Library/Frameworks/Python.framework) into the project and tried the most minimal program possible:
#include <boost/python.hpp>
int main(int argc, const char * argv[]) {
Py_Initialize();
Py_Finalize();
return 0;
}
and get:
/opt/local/include/boost/python/detail/wrap_python.hpp:50:11: fatal error: 'pyconfig.h' file not found
Do I need to explicitly add the framework header folder to the project's header search paths? That seems irregular... so hopefully I'm just misunderstanding something?

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!