Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Please ask technical questions in the appropriate category. Thank you!

Undefined symbol using static constexpr

Jacob BarrettJun 12 2017 — edited Jun 16 2017

The following code using static constexp on a class results in and undefined symbol the on the 12.5 linker but links fine in GCC, Clang and Visual C++.

test.h:

class Test {

public:

  static constexpr auto CONST_VALUE = "const value";

  static constexpr auto CONST_OTHER = "const other";

};

test.cpp:

#include <iostream>

#include "test.h"

int main() {

std::cout << Test::CONST_VALUE;

}

When compiled:

$ CC -std=c++11 test.cpp -o test

Undefined                       first referenced

symbol                             in file

Test::CONST_VALUE              test.o

[Hint: static member Test::CONST_VALUE must be defined in the program]

Notice no compiler error is given when processing the header and that only for the variable being accessed in the cpp file gives an error at link time.

-Jake

This post has been answered by Steve.Clamage-Oracle on Jun 13 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2017
Added on Jun 12 2017
4 comments
1,388 views