Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:46:55+00:00 2026-06-04T17:46:55+00:00

a.cpp const unsigned char whatever[123] = { /* … */ }; a.h extern const

  • 0

a.cpp

const unsigned char whatever[123] = { /* ... */ };

a.h

extern const unsigned char whatever[123];

b.cpp

#include "a.h"
unsigned char x = whatever[0];
// error: undefined reference to 'whatever'

Why do I get an undefined reference error? Without the const, the error goes away.

How do I share an array of constants among multiple translation units?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:46:57+00:00Added an answer on June 4, 2026 at 5:46 pm

    This is one of the quirks people run into, it’s simply a matter that you’ve defined an a.h header file which declares a const array of 123 chars, and assigned it external linkage. When it is included into the b.cpp file, you’re basically promising the compiler it’s going to find in some other translation unit.

    But, every const variable has a dark secret – it’s trapped inside its defining translation unit because it is implicitly given static linkage. You promised your compiler whatever will be shared across multiple translation units, but it is actually loyal to just one translation unit and doesn’t like to be shared. And, well, you know the rest.

    Resolve by explicitly stating extern in the implementation file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It made some errors like this: KDnsCache.cpp: In member function ‘unsigned int KDnsCache::GetName(const char*)’:
why do I get a discard qualifiers error: customExc.cpp: In member function ‘virtual const
ERROR CODE: CList<CString,const char*> test; ERROR INFO: ECLIPSE / UBUNTU 10 /home/latyas/workspace/CList/Debug/../test.cpp:7: undefined reference
error LNK2019: unresolved external symbol char * __cdecl BytesToString(unsigned char const *,unsigned int) (?BytesToString@@YAPADPBEI@Z)
g++ cv.cpp -o cv -I /usr/local/include/opencv -L /usr/local/lib -lm -lcv -lhighgui -lcvaux Error: /usr/bin/ld:
I get the following error: 1>c:\documents and settings\krzys\desktop\desktop icons\ollydbg\plugins\odbgscript\OllyLangCommands.cpp(3602): error C2593: 'operator =' is
sqlite3_column_text returns a const unsigned char*, how do I convert this to a std::string?
Header file #include <iostream> #include <cstring> const unsigned MaxLength = 11; class Phone {
MFC File: winctrl4.cpp (C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\src\mfc) CString CRichEditCtrl::GetSelText() const { ASSERT(::IsWindow(m_hWnd)); CHARRANGE
MinGw 4.7.0 Boost 1.47 code: #include <iostream> #include <boost/thread.hpp> int main(int argc, char *argv[])

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.