g++

GCC and ld can't find exported symbols…but they're there

微笑、不失礼 提交于 2019-12-23 23:07:39
问题 I have a C++ library and a C++ application trying to use functions and classes exported from the library. The library builds fine and the application compiles but fails to link. The errors I get follow this form: app-source-file.cpp:(.text+0x2fdb): undefined reference to `lib-namespace::GetStatusStr(int)' Classes in the library seem to be resolved just fine by the linker, but free functions and exported data (like a cosine lookup table) invariably result in the above error. I am using Ubuntu

name collision in C++

怎甘沉沦 提交于 2019-12-23 20:32:05
问题 While writing some code i came across this issue: #include <iostream> class random { public: random(){ std::cout << "yay!! i am called \n" ;} }; random r1 ; int main() { std::cout << "entry!!\n" ; static random r2; std::cout << "done!!\n" ; return 0 ; } When i try to compile this code i get the error error: ârandomâ does not name a type. When I use some different name for the class the code works fine. Seems like random is defined somewhere else(although the compiler message is not very

What's different between compiling in 32bit mode and 64bit mode on 64bit os about execution of ioctl function?

自作多情 提交于 2019-12-23 20:26:08
问题 I have a 64 bit Enterprice SuSE 11 I have an application which open a HIDRAW device and operate an ioctl function on it to get raw info from this device like below: struct hidraw_devinfo devinfo; int fd = open("/dev/hidraw0", 0); int ret = ioctl(fd, HIDIOCGRAWINFO, &devinfo); ... If I compile this program in 64 bit mode there is no error and no problem and when I execute the application the ioctl function works properly. g++ main.cpp If I complie this program in 32 bit mode there is also no

Clang: error: invalid use of non-static data member

寵の児 提交于 2019-12-23 19:58:25
问题 Is this gcc being overly nice and doing what the dev thinks it will do or is clang being overly fussy about something. Am I missing some subtle rule in the standard where clang is actually correct in complaining about this Or should I use the second bit of code which is basically the how offsetof works [adrian@localhost ~]$ g++ -Wall -pedantic -ansi a.cc [adrian@localhost ~]$ a.out 50 [adrian@localhost ~]$ cat a.cc #include <iostream> struct Foo { char name[50]; }; int main(int argc, char

Avoiding conflicting declaration errors in typedef c++

余生颓废 提交于 2019-12-23 18:45:57
问题 Is there a way I can make g++ ignore or work around conflicting typedefs? Background: I'm writing some c++ code for the gridlab_d simulator. My model needs to connect to a c++ database, so I'm using the mysql++ library. use of the mysql++ library requires me to link to the mysql library, so i compile with g++ -I/usr/include/mysql -I/usr/local/include/mysql++ Problem: both mysql.h and list.h in gridlab typedef a struct to have the name LIST . Here is the compiler error In file included from

c++0x_warning.h:31:2: error:

人盡茶涼 提交于 2019-12-23 16:34:40
问题 I was trying make a file and got this error. I am a newbie. Can any one help me here. /usr/include/c++/4.6/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options. How to enable with -std=c++0x ? I used this in my makefile #CXX_VERSION_FLAG = -std=c++0x but did not work. Thanks, Addy 回答1: No, just pass these

cmake: problems specifying the compiler

◇◆丶佛笑我妖孽 提交于 2019-12-23 15:39:07
问题 I have a problem with this CMakeLists.txt file: cmake_minimum_required(VERSION 2.6) SET(CMAKE_C_COMPILER C:\\MinGW\\bin\\gcc) SET(CMAKE_CXX_COMPILER C:\\MinGW\\bin\\g++) project(cmake_test) add_executable(a.exe test.cpp) Calling cmake with: cmake -G "MinGW Makefiles" I get: c:\cmake_test>cmake -G "MinGW Makefiles" . -- The C compiler identification is GNU 4.6.1 CMake Warning (dev) at CMakeFiles/CMakeCCompiler.cmake:1 (SET): Syntax error in cmake code at C:/cmake_test/CMakeFiles/CMakeCCompiler

How can I find C++ functions that should be const?

a 夏天 提交于 2019-12-23 14:53:48
问题 I have this code: #include <stdio.h> class A { public: int doit() { return 5; } int doit2() const { i++; return i; } int i; }; int main() { A a; printf("%d\n", a.doit() ); return 0; } Which compiles cleanly with g++ -Wall -Wpedantic main.cpp. Is there some way to get g++ to say "A::doit() should be marked as const"? g++ 4.8 has -Wsuggest-attribute=const but it doesn't seem to work in this case. g++ -Wall -Wpedantic -Wsuggest-attribute=const const_main.cpp -fipa-pure-const -O2 -Wextra is still

Can linking with the same library twice be a problem with g++?

蓝咒 提交于 2019-12-23 14:19:14
问题 I noticed that when I make my application with gcc and look at the output during the linking phase, I see the following lib included twice: /home/rb01/opt/trx-HEAD/gcc/4.2.4/lib/../lib64/libstdc++.so And so I was just wondering if this is a problem with g++ (gcc) or if the second one is simply ignored? Thanks! 回答1: If symbols in a library have already been resolved, the linker ignores them. With shared libraries, as in this case, the linker doesn't actually link anyway. With static (.a)

Is it necessary to reset rdbuf of cout, cerr, and clog if they have been changed to be redirected to a file?

£可爱£侵袭症+ 提交于 2019-12-23 13:13:58
问题 While trying to figure out how to answer https://stackoverflow.com/questions/33601384/what-is-the-file-descriptor-of-linuxs-environments-standard-logging-stream, I noticed a link to an answer to a related SO post. I tried the code in the above linked answer with g++ 4.8.4 and got segmentation error before the program terminated. Here's the program: #include <iostream> #include <fstream> int main() { std::ofstream of("cout.txt"); std::cout.rdbuf(of.rdbuf()); std::cout << "test. test. test." <<