本文给出了两个需要注意的问题:
1.源文件和静态库的位置:
|
下面是shell命令:
$ pkg-config --libs --cflags ncurses
-I/usr/include/ncurses -lncurses
$ gcc $(pkg-config --libs --cflags ncurses) curses_test.c -o curses_test
/tmp/cc74H73T.o:curses_test.c:(.text+0xf): undefined reference to `initscr'
/tmp/cc74H73T.o:curses_test.c:(.text+0x14): undefined reference to
`ncwrap_stdscr'
/tmp/cc74H73T.o:curses_test.c:(.text+0x2c): undefined reference to `wmove'
/tmp/cc74H73T.o:curses_test.c:(.text+0x31): undefined reference to
`ncwrap_stdscr'
/tmp/cc74H73T.o:curses_test.c:(.text+0x49): undefined reference to `waddnstr'
/tmp/cc74H73T.o:curses_test.c:(.text+0x4e): undefined reference to
`ncwrap_stdscr'
/tmp/cc74H73T.o:curses_test.c:(.text+0x56): undefined reference to `wrefresh'
/tmp/cc74H73T.o:curses_test.c:(.text+0x67): undefined reference to `endwin'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld:
/tmp/cc74H73T.o: bad reloc address 0x20 in section `.eh_frame'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld:
final link failed: Invalid operation
collect2: error: ld returned 1 exit status
$ gcc curses_test.c $(pkg-config --libs --cflags ncurses) -o curses_test
$ ./curses_test.exe
难道必须要把源文件 curses_test.c
放到 -I/usr/include/ncurses -lncurses
的前面吗?我在发行版本的Linux上面都没有出现这样的情况,当然版本最新的也才是4.8.1.
Archlinux的gcc 4.8.2上面没有这种情况,无论什么顺序都是可以正常编译的。
2.关于OpenMP
代码1
|
另一段代码:
|
On cygwin
g++ openmp_1.cpp -o openmp_1.exe
g++ openmp_2.cpp -o opemnp_2.exe -fopenmp
time 1937
time 2297
On MingW-g++ 4.8.1
g++ openmp_1.cpp -o openmp_1.exe
g++ openmp_2.cpp -o opemnp_2.exe -fopenmp
time 1975
time 492
On Visual Studio 2013
Openmp_2.cpp Project
C/C++ --> Language --> Open MP Support yes(/openmp)
time 1849
time 321