problem about linkage-Collection of common programming errors


  • Rüppell’s Vulture
    c global-variables extern linkage storage-class-specifier
    Here I have two files externdemo1.c and externdemo2.c.In the first file,I have declared and initialized a character array arr at file scope.But I have declared it in the second file externdemo2.c without the extern keyword and made use of it there in the function display(). Here are my confusions arising from it.Please answer these three://File No.1–externdemo1.c#include #include “externdemo2.c”extern int display(); char arr[3]={‘3′,’4′,’7’}; //extern char arr[3]={‘3′,’4′,’7’};/

  • Sean
    c++11 instantiation linkage explicit-instantiation
    In my class Foo, I need to construct an object using a helper function, and – as an arbitrary second function that helps force the structure of code – set a handler.Exposing the definition due to internal linkage seems like the only way to do this, but it offends my sense of style and I’m hoping I’ve overlooked another way of pulling this off. Here is a complete example that illustrates the point (makefile included, too!):// ideal_foo.hpp #ifndef IDEAL_FOO_HPP #define IDEAL_FOO_HPP#include #include #include namespace ideal {template class Foo : public std::enable_shared_from_this< Foo > {public:using FooType = Foo;using HandlerFunc = std::function;using Ptr = std::shared_ptr;static Ptr Init();~Foo() = default;void setHandler(HandlerFunc func);private:Foo();class Impl;std::unique_ptr impl_; };} // namespace ideal #endif // IDEAL_FOO_HPP// ideal_foo.cpp #include “ideal_foo.hpp”namespace ideal {template class Foo::Impl {public:HandlerFunc func_ = nullptr; };template typename Foo::Ptr Foo::Init() {return std::make_shared(); }template Foo::Foo() : impl_{new Impl{}} { }templatevoid Foo::setHandler(HandlerFunc func) {impl_->func_ = func; }} // namespace idealWhich compiles, and everything is gravy, until I try and use it externally.// ideal_bar.cpp #include “ideal_foo.hpp”namespace ideal { namespace {class Bar {public:using FooType

  • Simon
    iphone archive linkage beta-testing
    I am currently trying to archive my application for testing but it generate these error :Ld “/Users/Simon/Library/Developer/Xcode/DerivedData/Photo_Gallery-fycuagscgzkapvglqzfytatmaxzm/ArchiveIntermediates/Photo Gallery/IntermediateBuildFilesPath/Photo Gallery.build/Ad Hoc-iphoneos/Photo Gallery.build/Objects-normal/armv6/Photo Gallery” normal armv6cd “/Users/Simon/Desktop/Project/Photo Gallery”setenv IPHONEOS_DEPLOYMENT_TARGET 4.3setenv PATH “/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk “-L/Users/Simon/Library/Developer/Xcode/DerivedData/Photo_Gallery-fycuagscgzkapvglqzfytatmaxzm/ArchiveIntermediates/Photo Gallery/BuildProductsPath/Ad Hoc-iphoneos” “-L/Users/Simon/Desktop/Project/Photo Gallery/Photo Gallery/Admob” “-F/Users/Simon/Library/Developer/Xcode/DerivedData/Photo_Gallery-fycuagscgzkapvglqzfytatmaxzm/ArchiveIntermediates/Photo Gallery/BuildProductsPath/Ad Hoc-iphoneos” -F/

  • S_S
    sql linkage cross-join set-theory
    I’ve been struggling lately with a complex SQL query. I have the following tables: [dbo].[User] ~ {ID,nickname} [dbo].[Property] ~ {ID,title} [dbo].[Property_Values] ~ [ID,propertyID,title} [dbo].[Property_Values_User_Linkage] ~ {UserID,PropertyID,valueID} It’s basically a project in which a user chooses values for each property. Each property can be single-value or multi-value. For instance, user might choose multiple values for Property {ID=1,title=Hobbies} but must choose a single value for Property {ID=2,title=HairColor}.Using another table – [dbo].[Search_Property_Values_User_Linkage] – {UserID,PropertyID,valueID} I’m choosing what

  • moeCake
    c compiler-errors linkage
    I have following C program:#includestatic void p(void); static int c;int main(int argc,char **argv) {p();printf(“%d”,c);return 0; }void p(void) {printf(“From the Function P\n”); }int c=232;And the output error of compiler gcc is : error: non-static declaration of ‘c’ follows static declarationand when i looked in C standard ISO/IEC 9899:TC2:6.2.2 Linkages of identifiers1 An identifier declared in different scopes or in the same scope more than once can bemade to refer to the same object or function by a process called linkage.21) There arethree kinds of linkage: external, internal, and none.2 In the set of translation units and libraries that constitutes an entire program, each declaration of a particular identifier with external linkage denotes the same object or

  • user1042840
    c extern linkage
    I am aware about C linking rules presented in the following excerpts from C standard:1/ An identifier declared in different scopes or in the same scopemore than once can be made to refer to the same object or function bya process called linkage. There are three kinds of linkage: external,internal, and none.2/ In the set of translation units and libraries that constitutes anentire program, each declaration of a particular identifier withexternal linkage denotes the same object or function. Within onetranslation unit, each declaration of an identifier with internallinkage denotes the same object or function. Each declaration of anidentifier with

  • thokra
    c++ class c++11 namespaces linkage
    Consider a library exporting a distinct interface for initialization, which has to be called by the user before using anything else the library provides. In this step, certain system state is queried and stored in corresponding variables. This cannot be mapped to constants, but should also not be prone to changes due to writes from external sources, i.e. the system state should be queryable in different translation units but not writable.One obvious example is a timestamp marking the system startup. This cannot be a compile-time constant, but should also never be writable.This could be realized with a class implementing only static functions and using private, static members:// system.h #include using sys_ti

  • jason328
    ruby-on-rails ruby sqlite associations linkage
    I am very new to Rails and Web-programming and hope you can help me out with my very first project. I am developing a website for a Real Estate Agency.I have 3 tables in my database (Homes: Home_ID, Home_Name, Admin_ID; Admins: Admin_ID, Admin_Name, Admin_Email; Images: Image_

  • Neozaru
    c++ autotools automake libtool linkage
    I’m trying to build a library from Autotools (Automake/Libtool)My directory structure is :src/MyLib/*some_sources*.cpp/.h + a Makefile.am src/MyLib/Parsers/*some_other_sources.cpp/.h Makefile.amWhen I put all my source files in the same directory (so, no “Parse

  • Jeff Walden
    c++ c header-files linkage
    Typically one includes standard library headers in C++ in the global namespace, outside of any externs, like so:#include int main() { }But what’s specified to happen if you include a standard library header inside one? For example:extern

  • osgx
    c++ c++11 inline linkage c++03
    The standard says that given a declaration of inline void foo();that foo is an inline function with external linkage (because by default all function declarations have external linkage). This strikes me as odd. because the one definition rule section 3

  • n.m.
    c++ standards linkage
    Can an extern “C” function accept or return C++-specific data types, such as references, pointers-to-members, or non-POD classes (by value)? I cannot find anything in the C++ standard that forbids this. Logically, I would expect the standard to say som

  • Kuang Chen
    gcc makefile dependencies linkage
    It’s easy to let program figure out the dependency at compile time, (with gcc -MM). Nevertheless, link dependency (deciding which libraries should be linked to) seems

  • Paul Beckingham
    c++ templates linkage
    I converted a function to a template, and started getting this error. I must not be understanding a limitation of templates. Can someone tell me why this is broken?I am r

  • mindless
    c storage duration linkage
    Consider these examples:static int a; extern int a; //OK — what linkage does the a have now?static int a; int a; //ERRORextern int a; static int a; //ERRORint a; static int a; //ERRORextern

  • rkmax
    c++ cmake linkage
    I have a project with the following structure/cmake_modules/FindSFML.cmake/includes/car.hppmotor.hpptires.hpp/sources/car.cppmotor.cpptires.cpp /main.cpp/main.hppI have the following CMakeFiles.txtcmake_minimum_required(VERSION 2.8)project (MYGAME) set (MYGAME_VERSION_MAJOR 1) set (MYGAME_VERSION_MINOR

  • AVD
    c++ external linkage
    I have 2 files A.cpp and B.cpp which look something like A.cpp ———- class w { public:w(); };B.cpp ———– class w { public:w(); };Now I

  • arrows

  • Chubsdad
    c++ static linkage odr
    Yet another static question. I have read the following:What are static variables? file scope and static floats http://msdn.microsoft.com/en-us/library/s1sb61xd.aspxAnd I still fail to understand the following behavior: I have one h file:// StaticTest.h #include static int counter = 0;struct A

  • Shahbaz
    c gcc linkage
    First, see this example (I made this up for the sake of example, it’s not a real program):whatever.h#ifndef WHATEVER_H #define WHATEVER_Hvoid fill(void);#endifmain.c#include #include “whatever.h”char *names[10] = {NULL};int main() { int i; fill(); for (i = 0; i < 10; ++i)printf(“%s\n”, names[i]);return 0; }whatever.c#include “whatever.h”extern char **names;void fil

  • madmax
    c++ cmake undefined-reference linkage
    I have this code here: Main.cpp#include “AStarPlanner.h” #include int main(int argc, char** argv) {AStarPlanner planner = AStarPlanner(10,10,&costmap); }and my class: AStarPlanner.h class AStarPlanner {public:AStarPlanner(int width, int height, const costmap_2d::Costmap2D* costmap);vir

  • Duggs_Dojo
    c linkage
    Can Someone Explain this to me?The file a is as follows:file a.c #include #include loader constraint violation: loader (instance of org/codehaus/plexus/classworlds/ realm/ClassRealm) previously initiated loading for a different type with name “groovyjarjarantlr/TokenStream” 18:22:12.311 [ERROR] [org.gradle.BuildExceptionReporter] 18:22:12.311 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is: 18:22:12.311 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:sonarAnaly ze’. 18:22:12.327 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execut eActions(ExecuteActionsTaskExecuter.java:68) 18:22:12.327 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execut e(ExecuteActionsTaskExecuter.java:46) 18:22:12.327 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter .execute(PostExecutionAnalysisTaskExecuter.java:34) 18:22:12.342 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter$1.r un(CacheLockHandlingTaskExecuter.java:34) 18:22:12.342 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAccess. java:200) 18:22:12.342 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Default CacheAccess.java:172) 18:22:12.358 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Default CacheAccess.java:198) 18:22:12.358 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOper ation(DefaultPersistentDirectoryStore.java:111) 18:22:12.358 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAcce ss.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83) 18:22:12.374 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.exe cute(CacheLockHandlingTaskExecuter.java:32) 18:22:12.374 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute( SkipUpToDateTaskExecuter.java:55) 18:22:12.374 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(Va lidatingTaskExecuter.java:57) 18:22:12.389 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter. execute(SkipEmptySourceFilesTaskExecuter.java:41) 18:22:12.389 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.exe cute(SkipTaskWithNoActionsExecuter.java:51) 18:22:12.389 [ERROR] [org.gr

Originally posted 2013-11-09 23:31:00.