0

I have the problem that Eclipse CDT somehow does not understand the definition of methods, declared in header file, like: example of header y_sort_network.hpp:

    #pragma once
extern "C" {
#include <stdint.h>
}

namespace y_my{
static inline void ySortSingleUpto16(uint32_t * arr, uint32_t * to);
static inline void yMergex16(uint32_t * arr, uint32_t *to);

}

example of source y_sort_network.cpp:

#include "y_sort_network.hpp"
namespace y_my{

static inline void yMergex16(uint32_t * arr, uint32_t *to) {
// body ...
}
static inline void ySortSingleUpto16(uint32_t * arr, uint32_t * to) {
// body ...
}

}

then , this mwthod will not be found im main method, means they are declared but not linked :

 `sort_network_test.cpp:19:` undefined reference to `y_my::yMergex16(unsigned int*, unsigned int*)'

all files lies in the same folder, what is a source folder in properties

user184868
  • 193
  • 9
  • What do you intend `static` and `inline` to achieve here? – Useless Feb 14 '18 at 17:10
  • obvious, static because it is outside of a class and inline cause i want compiler to inline it – user184868 Feb 14 '18 at 17:12
  • 1
    Not obvious, that's not what `static` means (see [this question](https://stackoverflow.com/q/31305717/212858)), and that's also not really what `inline` does (see [this question](https://stackoverflow.com/q/1759300/212858)) – Useless Feb 14 '18 at 17:15

1 Answers1

0

Eclipse CDT somehow does not understand the definition of methods

Eclipse is an IDE, which is to say, a text editor with delusions of grandeur. The error you're getting is from the compiler the CDT plugin is running for you. I only mention this to explain why the eclipse-cdt tag isn't relevant and because I'm a terrible pedant.

extern "C" {
#include <stdint.h>
}

last bit of pedantry, I promise: you should just use

#include <cstdint>

if you have a vaguely recent conforming compiler.


Now, consider these two very similar looking declarations where static means two completely different things:

struct S {
  static void func();
};
namespace N {
  static void func();
};

The first declares a type S, and a static method S::func which does not operate on a specific instance of S. It doesn't say anything about the linkage of the symbol S::func.

In the second, there is no class for N::func to be a static member of (namespaces are not like classes in this respect because you can't have an instance of a namespace). Here, static describes the linkage of N::func, and means "not exported to other translation units".

Now consider your cpp file: you define your two functions with static linkage. That means the symbols aren't exported to other translation units, like your test program, which means your test program doesn't have access to any definition for those functions.

tl;dr - just remove the static keyword, it doesn't mean what you think it does (at file/namespace scope, anyway).

Useless
  • 64,155
  • 6
  • 88
  • 132
  • ok i removed both modifiers now it works. If you know good the stuff, probably you can tell how to fix CDT false error reports? – user184868 Feb 14 '18 at 17:48