user184868
user184868

Reputation: 183

Eclipse CDT does not understands of method definitions what are tthere

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

Upvotes: 0

Views: 124

Answers (1)

Useless
Useless

Reputation: 67772

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).

Upvotes: 0

Related Questions