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. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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

Processing
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,879 views