macos - MacOSX 10.6 上的 getline 崩溃 C 编译器?

标签 macos compiler-construction osx-snow-leopard getline

我很难安装需要在 C 中进行一些编译的 R 库。我正在使用 Mac OSX Snow Leopard 机器并尝试安装此 R 包(here)。

我看过the thread在 mac 上谈论 getline 并尝试了其中的一些修复,但没有任何效果!我是新手,不懂任何 C,所以这可能就是原因!谁能给我一些关于如何修改此包中的文件以安装它的提示?任何帮助将不胜感激!这是我收到的错误:


** libs
** arch - i386
g++ -arch i386 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386  -I/usr/local/include   -D_FASTMAP -DMAQ_LONGREADS   -fPIC  -g -O2 -c bed2vector.C -o bed2vector.o
In file included from /usr/include/c++/4.2.1/backward/strstream:51,
                 from bed2vector.C:8:
/usr/include/c++/4.2.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
bed2vector.C: In function ‘int get_a_line(FILE*, BZFILE*, int, std::string&)’:
bed2vector.C:74: error: no matching function for call to ‘getline(char**, size_t*, FILE*&)’
make: *** [bed2vector.o] Error 1
chmod: /Library/Frameworks/R.framework/Resources/library/spp/libs/i386/*: No such file or directory
ERROR: compilation failed for package 'spp'

最佳答案

最简单的解决方案可能是将 getline() 的静态定义添加到 bed2vector.c。这可能就足够了:

/* PASTE AT TOP OF FILE */
#include <stdio.h>   /* flockfile, getc_unlocked, funlockfile */
#include <stdlib.h>  /* malloc, realloc */

#include <errno.h>   /* errno */
#include <unistd.h>  /* ssize_t */

extern "C" ssize_t getline(char **lineptr, size_t *n, FILE *stream);

/* PASTE REMAINDER AT BOTTOM OF FILE */
ssize_t
getline(char **linep, size_t *np, FILE *stream)
{
  char *p = NULL;
  size_t i = 0;

  if (!linep || !np) {
    errno = EINVAL;
    return -1;
  }

  if (!(*linep) || !(*np)) {
    *np = 120;
    *linep = (char *)malloc(*np);
    if (!(*linep)) {
      return -1;
    }
  }

  flockfile(stream);

  p = *linep;
  for (int ch = 0; (ch = getc_unlocked(stream)) != EOF;) {
    if (i > *np) {
      /* Grow *linep. */
      size_t m = *np * 2;
      char *s = (char *)realloc(*linep, m);

      if (!s) {
        int error = errno;
        funlockfile(stream);
        errno = error;
        return -1;
      }

      *linep = s;
      *np = m;
    }

    p[i] = ch;
    if ('\n' == ch) break;
    i += 1;
  }
  funlockfile(stream);

  /* Null-terminate the string. */
  if (i > *np) {
    /* Grow *linep. */
      size_t m = *np * 2;
      char *s = (char *)realloc(*linep, m);

      if (!s) {
        return -1;
      }

      *linep = s;
      *np = m;
  }

  p[i + 1] = '\0';
  return ((i > 0)? i : -1);
}

这不处理行长于 ssize_t 可以表示的最大值的情况。如果您遇到这种情况,您可能会遇到其他问题。

关于macos - MacOSX 10.6 上的 getline 崩溃 C 编译器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4160353/

相关文章:

android - Mac 上的 Meteor 1.3.3 运行 android : Android target: Android SDK not found

ios - iOS/OSX 框架中的数据绑定(bind)

linux - 如何通知 GCC 不使用特定寄存器

c - Solaris cc 是否在可执行文件中嵌入了不同编译的不同信息?

parsing - 为动态语言创建单独的“ bool 表达式”规则

ruby-on-rails - 在 Snow Leopard 上安装 Rails 3.1 和 Postgresql

PostgreSQL 错误 'Could not connect to server: No such file or directory'

macos - 是否可以在 Mac OS 上调试 x64 程序集?

vba - AppleScriptTask 抛出错误 5 - 无效的过程调用或参数

java - 如何跨更新在 Mac 上保留 CAcerts keystore ?