linker

How to avoid multiple definition linking error?

左心房为你撑大大i 提交于 2020-01-02 02:20:31
问题 Beside moving the hello() function into another source (.cpp) file or renaming the function. Is there any other methods to avoid the linking error? staticLibA.h #ifndef _STATIC_LIBA_HEADER #define _STATIC_LIBA_HEADER int hello(void); int hello_staticLibA_only(void); #endif staticLibA.cpp #include "staticLibA.h" int hello(void) { printf("\nI'm in staticLibA\n"); return 0; } int hello_staticLibA_only(void) { printf("\nstaticLibA: hello_staticLibA_only\n"); return 0; } output: g++ -c -Wall -fPIC

error LNK2001 __imp_fprintf Visual Studio 2015 RC

牧云@^-^@ 提交于 2020-01-02 01:32:09
问题 I recently was forced to upgrade from Visual Studio 2015 Pre-Release to Visual Studio 2015 Release Candidate as a result of an expired license. My project was previously building fine, however, now it is not. I am getting only two link errors and I've spent the last two days attempting to address them: 1>SDL2main.lib(SDL_windows_main.obj) : error LNK2001: unresolved external symbol __imp_fprintf 1>SDL2main.lib(SDL_windows_main.obj) : error LNK2001: unresolved external symbol __imp___iob_func

With gcc, include strictly C99 symbols, specifically excluding POSIX

允我心安 提交于 2020-01-02 01:15:12
问题 I am taking a course in C after many years programming. My instructor is not using a POSIX machine, and I was recently penalized for using the index function in an assignment. I did some research and I notice that while index was an early part of AT&T Unix and is POSIX-compliant, it is not part of the C99 standard. I'd like gcc to help me find use of similar symbols . I am compiling on OSX with gcc 4.2 ( not llvm) My first leg of research involved noticing that my string.h file wraps the

static const in c++ class: undefined reference

我的未来我决定 提交于 2020-01-02 00:26:26
问题 I have a class for local use only (i.e., its cope is only the c++ file it is defined in) class A { public: static const int MY_CONST = 5; }; void fun( int b ) { int j = A::MY_CONST; // no problem int k = std::min<int>( A::MY_CONST, b ); // link error: // undefined reference to `A::MY_CONST` } All the code reside in the same c++ file. When compiling using VS on windows, there is no problem at all. However, when compiling on Linux I get the undefined reference error only for the second

Xcode returns linker error “library not found for -lFirebaseAuth”

与世无争的帅哥 提交于 2020-01-02 00:03:11
问题 I wanted to test firebase initial app on Unity. I made a build from Unity in macOS and in Xcode project folder, I have runned the pod command successfully. pod install After this I opened Xcode project and I clicked to build button. Before this, I was getting framework not found error. I fixed it and now I am getting ld: warning: directory not found for option '-L/Users/ali/Library/Developer/Xcode/DerivedData/Unity-iPhone-giljorflztrrychfchrkhcfbqtbh/Build/Products/ReleaseForRunning-iphoneos

Garbage from other linking units

こ雲淡風輕ζ 提交于 2020-01-01 11:47:12
问题 I asked myself the following question, when I was discussing this topic . Are there cases when some unused code from translation units will link to final executable code (in release mode of course) for popular compilers like GCC and VC++? For example suppose we have 2 compilation units: //A.hpp //Here are declarations of some classes, functions, extern variables etc. And source file //A.cpp //defination of A.hpp declarations And finally main //main.cpp //including A.hpp library #include "A

Why do I get a multiple definition error while linking?

不打扰是莪最后的温柔 提交于 2020-01-01 10:51:54
问题 I use these two files here and here. I created a class in two separate files: modul1.h #ifndef MODUL1_H #define MODUL1_H #include <iostream> #include <fstream> #include "easylogger.h" class Modul1 { public: Modul1(std::string name); protected: private: easylogger::Logger *log; }; #endif // MODUL1_H and modul1.cpp #include "modul1.h" Modul1::Modul1(std::string name):log(new easylogger::Logger(name)) { //ctor //std::ofstream *f = new std::ofstream(name.c_str(), std::ios_base::app); //log-

Linking a dynamic library (libjvm.dylib) in Mac OS X (rpath issue)

怎甘沉沦 提交于 2020-01-01 08:27:07
问题 I do have an application that requires linkage with libjvm (a library from the JDK needed to do JNI bindings). When I tell the location of libjvm.dylib using -L it successfully compiles and links. However when I run the binary I get: dyld: Library not loaded: @rpath/libjvm.dylib Referenced from: <my home directory>/./mybinary Reason: image not found So far I found out that I can run my binary specifying LD_LIBRARY_PATH like so: LD_LIBRARY_PATH=<path to libfolder installation> ./mybinary But

Valgrind reports uninitialized values on empty C program

时间秒杀一切 提交于 2020-01-01 08:02:07
问题 I have this C program compiled with either gcc test.c or clang test.c : int main (void) { return 0; } valgrind ./a.out gives me this: ==9232== Memcheck, a memory error detector ==9232== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==9232== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==9232== Command: ./a.out ==9232== ==9232== Conditional jump or move depends on uninitialised value(s) ==9232== at 0x4017876: index (in /usr/lib/ld-2.16.so) ==9232== by

How can I find the full file path given a library name like libfoo.so.1?

假如想象 提交于 2020-01-01 07:59:07
问题 Without implementing a linker or using ldd , how can I find the full path to a library? Is there a standard library available for that on Linux? (POSIX maybe?) Using ldd and grep on a file that is knowingly using libGL.so.1 , it looks like: $ ldd /usr/bin/glxinfo | grep libGL libGL.so.1 => /usr/lib/libGL.so.1 (0x00007f34ff796000) Given a library name like libGL.so.1 , how can I find the full path /usr/lib/libGL.so.1 ? . Preferably accepting an option for finding 32-bit and 64-bit libraries.